Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change URL in an iframe using javascript

I have a in an iframe, that calls a function from the parent page. The function is window.location, however this does not change the url. Is there a way to have the iframe call a function from the parent page, that will cause the iframe to change url? I also had a basic qustion, if I have an iframe, and click on a link that brings me to a new page, does the parent page remain open?

Thanks in advance for your help. Sorry if I sound like a complete idiot, I am new to javascript.

Dave

like image 590
Dave Smith Avatar asked Aug 12 '11 06:08

Dave Smith


1 Answers

window.location is not a function, it s an object.

To do what you want, first make the iframe call a special function from it's parent.

parent.sendMeToGoogle();

And in the function (in parent) do something like:

function sendMeToGoogle(){
    document.getElementById('iframeID').src="http://google.com/";
}
like image 195
Christian Avatar answered Nov 08 '22 10:11

Christian