“drop”事件后如何停止重定向? [英] How to stop redirecting after `drop` event?

查看:138
本文介绍了“drop”事件后如何停止重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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?

更新:

我发现了一些关于 html5doctor的提示


要告诉浏览器,我们可以放在这个元素中,我们要做的就是
取消拖拉事件。但是,由于IE的行为方式不一样,所以我们需要为
做同样的事情。

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 声明


dragenter dragover 事件的侦听器用于
表示有效的放置目标,那就是拖放的项目可能会
的地方被删除。

A listener for the dragenter and dragover events are used to indicate valid drop targets, that is, places where dragged items may be dropped.

但是我测试这个演示在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”事件后如何停止重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆