简体   繁体   English

拖放禁用在Safari / Chrome WebKit浏览器中不起作用

[英]Drag-Drop disabling not working in Safari/Chrome WebKit Browsers

I have created a Rich Text Editor Web application using document.designMode="on" in an iframe. 我已经在iframe中使用document.designMode =“ on”创建了Rich Text Editor Web应用程序。 I want the selection of text to work but want the drag and dropping of text to be disabled. 我希望选择文本,但希望禁用文本的拖放。 I tried this: 我尝试了这个:

evt.dataTransfer.effectAllowed="none";
evt.dataTransfer.dropEffect = "none";

This works fine in Firefox but it doesn't work in Safari/Chrome WebKit browsers. 在Firefox中可以正常使用,但在Safari / Chrome WebKit浏览器中则无法使用。 I have tried to put this in every event: dragover, dragstart, drag, dragenter etc.. but to no avail..putting evt.preventDefault() in mousedown or mouseup addEventListeners disables the selection of text which I don't want .please help... 我试图将其放在每个事件中:dragover,dragstart,drag,dragenter等。但无济于事..在mousedown或mouseup中将evt.preventDefault()放入addEventListeners会禁用我不需要的文本的选择。请救命...

Ok here I can see the same issue as mine, I've been working on these last month and I just got lucky to solve using using trial and error. 好的,在这里我可以看到与我相同的问题,我上个月一直在研究这些问题,我很幸运能够使用试错法解决。 I was using Asp.net MVC and Safari and Chrome does not include scripts created on the views that has content place holders mapped in the header of the masterpage if you understand what I mean. 我使用的是Asp.net MVC和Safari,如果您了解我的意思,Chrome浏览器不包含在视图上创建的脚本,这些视图的内容占位符映射在母版页的标题中。

In your scenario you might need to check your javascript if it was successfully invoked by the time that the function was called. 在您的情况下,您可能需要检查JavaScript,如果在调用该函数时是否成功调用了它。 Like for example you add a library 例如,您添加一个库

make sure that it is on the header and when you try to call a function say for example: 确保它在标题上,并且在您尝试调用函数时说出例如:

function Drag(){ 函数Drag(){

// Alert to prove that this Drag method was really called //警告以证明此Drag方法确实已被调用

alert("Drag method was called"); alert(“ Drag方法被调用”);

} }

Using alerts will help you to check if your function was successfully executed although alerts are annoying but if you use it wisely it would surely help you in debugging. 使用警报将帮助您检查功能是否已成功执行(尽管警报很烦人),但是如果您明智地使用它,则肯定会有助于调试。 And most of the time it is also helpful if you can put all your scripts in the header part although some situations can't be avoided. 在大多数情况下,尽管无法避免某些情况,但是可以将所有脚本放在标头部分中也很有帮助。

This worked for me in my Safari/Chrome javascript issues. 这对我的Safari / Chrome JavaScript问题有效。

Please vote if it helped you. 如果有帮助,请投票。 Thank you! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM