How to change iframe source?

Member

by jasen , in category: Javascript , 12 days ago

How to change iframe source?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by muriel.schmidt , 11 days 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.