How to navigate URL in an iframe with JavaScript
The src attribute of an iframe element defines the URL of the document that can be displayed in an iframe.
To navigate a URL in an iframe with JavaScript, we need to set the src attribute or pass the value of the src attribute to an iframe element.
document.querySelector('iframe').src = 'url'
The following example will set the iframe src dynamically.
Example : navigate URL in an iframe with JavaScript #
<iframe src="" width="300" height="200"></iframe>
<button onclick="myFunc()">Click Me</button>
<script>
function myFunc(){
document.querySelector('iframe').src='https://www.3schools.in/p/example.html';
}
</script>
save
listen
AI Answer
How to navigate URL in an iframe with JavaScript
0
The src attribute of an iframe element defines the URL of the document that can be displa…
asked
Apu
0 answers
2915
The src attribute of an iframe element defines the URL of the document that can be displa…
Answer Link
answered
Apu