如何禁用JavaScript中的iframe? [英] How to disable an iframe in javascript?

查看:168
本文介绍了如何禁用JavaScript中的iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Javascript禁用iframe,以便用户无法与iframe的内容交互(即滚动,选择,拖动等)?例如,iframe中的Google地图通常可以被拖动和缩放。如何防止这些操作?

How can an iframe be disabled using Javascript, such that the user is unable to interact with the iframe's contents (i.e. scrolling, selecting, dragging, etc)? For example, a Google map in an iframe can normally be dragged and zoomed. How would these actions be prevented?

推荐答案

如果你想禁用鼠标交互,这应该可以。

If you're wanting to disable mouse interaction, this should work.

将DIV放在iframe的顶部,就像这样(用你自己的替换顶部,左边,宽度和高度值):

Put a DIV over the top of your iframe, like so (replace top, left, width and height values with your own):

<div id="blank" style="display:none; position:absolute; top:100px; left:100px; width:600px; height:400px;">

当您要禁用iframe时,请在javascript中执行此操作:

and when you want to disable the iframe, do this in javascript:

document.getElementById("blank").style.display="block";

这篇关于如何禁用JavaScript中的iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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