How to disable an iframe in javascript? [closed]

2019-02-12 18:23发布

问题:

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.