為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

how to stop ctrl-v from modifying UI

  • 4 回覆
  • 1 有這個問題
  • 1 次檢視
  • 最近回覆由 smiske

more options

I am trying to stop Ctrl-V from modifying the UI. When someone types Ctrl-V the field becomes 0 or blank. The fields that are a problem are Read Only fields, so they should never change.

<input name="__Update_RWRadiusofOperation_13010_472_Int__Ctrl" value="50" readonly="readonly" id="__Update_RWRadiusofOperation_13010_472_Int__Ctrl" placeholder="Radius of Operation" onpaste="return('false')" input="DontAllowPaste()" onkeydown="DontAllowPaste()" class="form-control" style="color:#00ff00!important;" type="text">

Dontallowpaste() return false;

the above code is from after I have pressed Ctrl-V the screen shows 0, but above it shows 50

I am trying to stop Ctrl-V from modifying the UI. When someone types Ctrl-V the field becomes 0 or blank. The fields that are a problem are Read Only fields, so they should never change. <input name="__Update_RWRadiusofOperation_13010_472_Int__Ctrl" value="50" readonly="readonly" id="__Update_RWRadiusofOperation_13010_472_Int__Ctrl" placeholder="Radius of Operation" onpaste="return('false')" input="DontAllowPaste()" onkeydown="DontAllowPaste()" class="form-control" style="color:#00ff00!important;" type="text"> Dontallowpaste() return false; the above code is from after I have pressed Ctrl-V the screen shows 0, but above it shows 50
附加的畫面擷圖

被選擇的解決方法

I have tried so many different things based on what I have googled and I am not sure why this didn't originally work for chrome, but this now works across all the browsers that run under windows

TextControl.Style.Add("color", "#00ff00!important") TextControl.Attributes.Add("onkeydown", "return(false)")

從原來的回覆中察看解決方案 👍 0

所有回覆 (4)

more options

I get the desired results in Firefox if I set dom.event.clipboardevents.enabled = false. Is there a way to programmatically set something on each object or does it really need to be at the browser level or can you fix Firefox not to have this behavior of modifying the value with invalid info.

more options

That's puzzling because readonly should be all you need. What else is going on in the page that might be bypassing readonly? Can you post a stripped down test case that demonstrates the problem?

Also, I don't think this makes sense:

onpaste="return('false')"

unless you have other code that looks for the text false.

For testing, you could try:

onpaste="console.log('Paste intercepted'); return false;"

more options

smiske said

<input name="__Update_RWRadiusofOperation_13010_472_Int__Ctrl" value="50" readonly="readonly" id="__Update_RWRadiusofOperation_13010_472_Int__Ctrl" placeholder="Radius of Operation" onpaste="return('false')" input="DontAllowPaste()" onkeydown="DontAllowPaste()" class="form-control" style="color:#00ff00!important;" type="text">

Also, I don't think "input" is a valid attribute in the "input" tag. Please test without it in case that is confusing Firefox.

more options

選擇的解決方法

I have tried so many different things based on what I have googled and I am not sure why this didn't originally work for chrome, but this now works across all the browsers that run under windows

TextControl.Style.Add("color", "#00ff00!important") TextControl.Attributes.Add("onkeydown", "return(false)")