本文介绍了如何使用支持chrome浏览器的javascript清除clipboarddata?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 存储当前复制值的剪贴板。 我可以使用javascript获取当前在剪贴板中的当前值,我使用的是Chrome浏览器,但我无法修改剪贴板值或清理剪贴板数据。因为我要设计一个系统,其中一旦我粘贴复制的值,它应该被删除或从剪贴板中删除。当我再次尝试粘贴该值时,不应该粘贴它。 帮助 我尝试过: document.addEventListener(粘贴,函数(e){ var clipText = e.clipboardData.getData('Text '); clipText = clipText.toUpperCase(); console.log(e.target.id); if(temp2 == clipText) count = count + 1; e.preventDefault(); if(clipText!= null&& count == 0) { e.target.value = clipText ; temp2 = clipText; } else if(temp2 != clipText){ e.target.value = clipText; temp2 = clipText; }否则{ if(temp2 == clipText&&数> 0) { e.target.value =; } } 返回false; }); Clipboard in which current copied value is stored.I can get the current value which is currently in clipboard using javascript and i am using chrome browser but i am unable to modify the clipboard value or clean clipboard data.because i ahve to design a system in which once i paste the copied value ,it should be deleted or remove from clipboard. when i try to paste again that value ,it should not be pasted.HelpWhat I have tried:document.addEventListener("paste", function (e) { var clipText = e.clipboardData.getData('Text'); clipText=clipText.toUpperCase(); console.log(e.target.id); if(temp2==clipText) count=count+1; e.preventDefault(); if(clipText!=null && count==0) { e.target.value = clipText ; temp2=clipText; } else if(temp2!=clipText ){ e.target.value = clipText ; temp2=clipText; }else{ if(temp2==clipText && count>0 ) { e.target.value = "" ; } } return false; });推荐答案 没有方法可以检测到另一个应用程序已从剪贴板粘贴数据。将数据放入剪贴板后,数据将由系统拥有,并可由任何其他应用程序查询。 所有你能做的就是清除剪贴板时你的申请正在粘贴。但是你不应该这样做,因为数据可能来自任何应用程序,用户可能想要多次粘贴它。 您可能想要通过Drag提供数据&安培;请改为删除,因为它正在执行您想要的操作:删除数据或取消拖动操作后,数据将被销毁。There is no method to detect that another application has pasted data from the clipboard. Once data has been put on the clipboard, the data is owned by the system and can be queried by any other application.All you can do is clearing the clipboard when your application is pasting. But you should not do so because the data may be from any application and the users might want to paste it multiple times.You might want to provide the data by Drag & Drop instead because that is doing what you want: Once data are dropped or the drag operation is cancelled, the data are destroyed. 这篇关于如何使用支持chrome浏览器的javascript清除clipboarddata?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-10 17:49