问题描述
在Firefox中将文件放入 div
中后,该网页将被重定向到此文件。我尝试使用jQuery的 e.preventDefault()
在 drop
处理程序中停止这种传播,并失败。
After dropping a file into a div
in Firefox, the webpage will be redirected to this file. I tried to stop this propagation using jQuery's e.preventDefault()
in drop
handler, and failed.
请参阅,将文件放入 #test
不会重定向网页,而是放入#test1
中,我想知道为什么。我应该始终将处理程序绑定到 dragenter
, dragover
, dragleave
和 drop
以防止在下降之后传播
?
See this demo, dropping a file into #test
won't redirect the webpage, but dropping into #test1
will, I want to know why. Should I always bind handlers to dragenter
, dragover
, dragleave
and drop
to prevent propagation after drop
?
更新:
我发现了一些关于:
Mozilla :
但是我测试在firefox, #test
的作品和#test1
不会,似乎Mozilla犯了一个错误,html5doctor是正确的:Firefox需要 dragover
只使 drop
work。
But I test this demo on firefox, #test
works and #test1
doesn't, seems Mozilla made a mistake, and html5doctor is right: Firefox needs dragover
only to make drop
work.
推荐答案
ondragover
事件需要在 Google Chrome 和 Safari 中取消,以便触发 ondrop
事件。
The ondragover
event needs to be canceled in Google Chrome and Safari to allow firing the ondrop
event.
这篇关于“drop”事件后如何停止重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!