How to disable iframe from javascript?

Member

by darion , in category: HTML & CSS , 3 months ago

How to disable iframe from javascript?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by mallory_cormier , 3 months ago

@darion 

To disable an iframe using JavaScript, you can set the src attribute of the iframe to an empty string. Here is an example code snippet:

1
2
var iframe = document.getElementById('myFrame');
iframe.src = '';


This will effectively disable the iframe and it will not load any content. You can also hide the iframe by setting its display property to none:

1
iframe.style.display = 'none';


Additionally, you can remove the iframe from the DOM entirely by using the removeChild method:

1
iframe.parentNode.removeChild(iframe);


These methods will disable the iframe and prevent it from being displayed or loading any content.