How to change iframe source?

Member

by jasen , in category: Javascript , 8 months ago

How to change iframe source?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by muriel.schmidt , 8 months ago

@jasen 

To change the source of an iframe, you can use JavaScript to dynamically set the "src" attribute of the iframe element. Here's how you can do it:

  1. Get a reference to the iframe element:
1
var iframe = document.getElementById("your-iframe-id");


  1. Set the new source URL:
1
var newSourceUrl = "http://example.com/newpage.html";


  1. Update the src attribute of the iframe element:
1
iframe.src = newSourceUrl;


By following these steps, you can change the source of an iframe dynamically using JavaScript.

Related Threads:

How to change the size of iframe?
How to change the height of an iframe with javascript?
How to change the font family in an iframe?
How to change height of iframe when it loads?
How to change src function in iframe?
How to change height and width of an iframe?