Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a javascript function to load a page in an iFrame

I'm trying to use a Javascript function to load a web page in an iframe named "cake". How can I do that?

<html>
  <head>
  </head>
  <body>
    <button onclick=[function]>Load page in iframe</a>
  </body>
</html>
like image 788
MistaBoodadee Avatar asked Sep 25 '15 20:09

MistaBoodadee


2 Answers

function changeUrl() {
    var site = "https://www.google.com/";
    document.getElementsByName('iFrameName')[0].src = site;
}
    <html>
      <head>
      </head>
        <body>
          <button onclick="changeUrl()">Load page in iframe</button>
          <iframe name="iFrameName"></iframe>
        </body>
    </html>
like image 62
Sanket Bajoria Avatar answered Oct 20 '22 17:10

Sanket Bajoria


This worked:

<html>

<head>


<script type="text/javascript">

function changeUrl() {
    var site = "1.wav";
    document.getElementsByName('cake')[0].src = site;
}


</script>


</head>

<body>


<center>

<iframe src="http://www.w3schools.com" height=400 width=400 frameborder=0 name = "cake" style =""></></iframe>

<br>

<br>

<button onclick="changeUrl()">Load page in iframe</button>

</center>


</body>

</html>
like image 40
MistaBoodadee Avatar answered Oct 20 '22 17:10

MistaBoodadee