javascript - Prevent all JS events inside <iframe> - Stack Overflow

I want to display an <iframe> in my site, but I want the site that I am displaying to only be scr

I want to display an <iframe> in my site, but I want the site that I am displaying to only be scrollable. All other events should be disabled.

So that the container of the <iframe>, the <iframe> has a width and height of 100%, behaves as if it has nothing inside it.

Almost like it is a scrollable screenshot of the site. So on hover and on click inside the <iframe> don't work.

The reason I am doing this is that the container of the <iframe> needs to be draggable, but can't be dragged as all events on the <iframe> are being registered within the <iframe>.

How can I do this in javascript and / or jQuery?

Can I apply a .preventDefault() to everything except scrolling?

I want to display an <iframe> in my site, but I want the site that I am displaying to only be scrollable. All other events should be disabled.

So that the container of the <iframe>, the <iframe> has a width and height of 100%, behaves as if it has nothing inside it.

Almost like it is a scrollable screenshot of the site. So on hover and on click inside the <iframe> don't work.

The reason I am doing this is that the container of the <iframe> needs to be draggable, but can't be dragged as all events on the <iframe> are being registered within the <iframe>.

How can I do this in javascript and / or jQuery?

Can I apply a .preventDefault() to everything except scrolling?

Share edited Jun 11, 2013 at 19:04 Ian 51k13 gold badges104 silver badges111 bronze badges asked Jun 11, 2013 at 18:51 Django JohnsonDjango Johnson 1,4494 gold badges23 silver badges41 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You could overlay a div with opacity: 0 (meaning it's fully transparent). That div will intercept most events, such as onclick.

You can then add a mousedown listener to that div which will initiate the 'drag'. The iframe then moves with the transparent div.

This will also disable scrolling though, but maybe you can mirror a scroll event from the div to the iframe .. will be tricky.

Set up a clear div on top of it, if you can use CSS, set the opacity to zero, and set the z-index to 1 on the div, and to -1 on the iframe. Doing that should make the div receive the mousedown events. You could also do document.getElementById("id").onclick=function(){} and make nothing happen on them

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745061390a4608988.html

相关推荐

  • javascript - Prevent all JS events inside &lt;iframe&gt; - Stack Overflow

    I want to display an <iframe> in my site, but I want the site that I am displaying to only be scr

    19小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信