How to load page dynamically in iframe?

by giovanny.lueilwitz , in category: Javascript , a year ago

How to load page dynamically in iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by aniya.jaskolski , a year ago

@giovanny.lueilwitz 

To load a page dynamically in an iframe, you can use JavaScript to set the src attribute of the iframe element. Here's an example:

  1. First, add an iframe element to your HTML with an id to identify it, like this:
1
<iframe id="myFrame"></iframe>


  1. Then, retrieve the iframe element using JavaScript:
1
var iframe = document.getElementById('myFrame');


  1. Finally, set the src attribute of the iframe to the desired URL:
1
iframe.src = 'https://example.com';


You can programmatically change the src attribute as needed to load different pages dynamically.