Iframe窃取鼠标事件 [英] Iframe stealing mouse events

查看:226
本文介绍了Iframe窃取鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上使用了一个Javascript滚动器类,可以无缝地将滚动条添加到页面上所有预定义的元素上,而这些元素都有溢出的内容。客户最近要求其中的一个元素包含一个iframe,这样他们就可以轻松地将交互式内容添加到这个区域。 (我知道,我知道,iframe,但我是这个工作的分包商,没有多少拉。)幸运的是,iFram的内容是从同一个域,所以我可以调整iframe的大小,一旦内容加载,依次触发Javascript滚动条。最后它在Chrome中运行的非常好。



在资源管理器和Firefox中,只要鼠标移到iframe上,iframe似乎就是在窃取鼠标事件。所以mousewheel事件不再起作用。您仍然可以拖动滚动手柄进行滚动,也可以单击滚动轨道上的任意位置,但使用滚轮不会执行任何操作。它甚至不会触发事件。



我已经看到其他人有类似的问题,但还没有找到解决办法。任何人有任何建议吗?



这是Scroll类的好办法: http://hastebin.com/xisidogiju.coffee



感谢任何帮助!

解决方案

鼠标事件绑定到窗口,iframe是窗口。它是一个奇迹,它可以在webkit浏览器中使用,就像你说的那样。

当鼠标移动到父窗口和iframe之间时,需要传递eventListener和eventHandler。

有关在iframe之间传递对象的引用: http://www.dyn-web.com/tutorials/iframes/refs.php


I'm using a Javascript scroller class on a site that seamlessly takes care of adding a scrollbar to all predefined elements on the page that have overflown content. The client has recently asked that one of these elements contain an iframe so they can easily add interactive content to this area. (I know I know, iframes, but I'm a subcontractor on this job. Not much pull.) Fortunately the content of the iFram is being pulled from the same domain, so I'm able to resize the iframe once the content loads, in turn firing the Javascript scrollbar. In the end it works beautifully—in Chrome.

In Explorer and Firefox the iframe seems to be stealing mouse events as soon as the mouse is over the iframe. So the mousewheel event no longer works. You can still drag the scroll handle to scroll, or click anywhere on the scroll track, but using the mousewheel does nothing. It doesn't even fire the event.

I've seen that others have had similar issues, but haven't found a workaround. Anyone have any suggestions?

Here's the Scroll class for good measure: http://hastebin.com/xisidogiju.coffee

Appreciate any help I can get!

解决方案

Mouse events are tied to windows, iframes are windows. Its a miracle this works in webkit browsers as you say.

You need to pass the eventListener and perhaps eventHandler between your parent window and the iframes when the mouse moves into them.

Some reference about passing objects between iframes: http://www.dyn-web.com/tutorials/iframes/refs.php.

这篇关于Iframe窃取鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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