Web Tools Table Maker3schools TranslateImage CompressorFavicon Icon GeneratorCrop & Resize Image
Apu
Apu November 20, 2022 › #HowTo #Iframe

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
Write Your Answer
loading
back
View All