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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If you're wanting to disable mouse interaction, this should work.
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;">
and when you want to disable the iframe, do this in javascript:
document.getElementById("blank").style.display="block";
回答2:
I don't know if you can use the disabled
property like input elements, but you could disable mouse interaction by placing an element over the iframe
, though this doesn't stop a user from tabbing to it.
Probably the best bet is to set the src
attribute to blank, but this will make the iframe
blank, not blurred.