Skip to content Skip to sidebar Skip to footer

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?

Solution 1:

functionchangeUrl() {
    var site = "https://www.google.com/";
    document.getElementsByName('iFrameName')[0].src = site;
}
<html><head></head><body><buttononclick="changeUrl()">Load page in iframe</button><iframename="iFrameName"></iframe></body></html>

Solution 2:

This worked:

<html><head><scripttype="text/javascript">functionchangeUrl() {
    var site = "1.wav";
    document.getElementsByName('cake')[0].src = site;
}


</script></head><body><center><iframesrc="http://www.w3schools.com"height=400width=400frameborder=0name = "cake"style =""></></iframe><br><br><buttononclick="changeUrl()">Load page in iframe</button></center></body></html>

Post a Comment for "Using A Javascript Function To Load A Page In An Iframe"