问题描述
在 Firefox 中将文件放入 div 后,网页将被重定向到该文件.我试图在 drop 处理程序中使用 jQuery 的 e.preventDefault() 来阻止这种传播,但失败了.
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 不会't 重定向网页,但放入 #test1 会,我想知道为什么.我是否应该始终将处理程序绑定到 dragenter、dragover、dragleave 和 drop 以防止在 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?
更新:
我在 html5doctor 上找到了一些提示:
I found some tips on html5doctor:
要告诉浏览器我们可以放入这个元素,我们所要做的就是取消拖动事件.然而,由于 IE 的行为不同,我们需要对 dragenter 事件做同样的事情.
To tell the browser we can drop in this element, all we have to do is cancel the dragover event. However, since IE behaves differently, we need to do the same thing for the dragenter event.
和 Mozilla 声明:
And Mozilla claims:
dragenter 和 dragover 事件的监听器用于指示有效的放置目标,即拖动项目可能的位置被丢弃.
A listener for the
dragenteranddragoverevents are used to indicate valid drop targets, that is, places where dragged items may be dropped.
但我在 firefox 上测试了 这个演示,#test 有效并且#test1 没有,看来 Mozilla 犯了一个错误,而 html5doctor 是对的:Firefox 只需要 dragover 才能使 drop 工作.
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"事件后停止重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!




大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)