Skip to content Skip to sidebar Skip to footer

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 f

Solution 1:

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:

functionsendMeToGoogle(){
    document.getElementById('iframeID').src="http://google.com/";
}

Solution 2:

If what you really need is to change the parent URL, you can use window.top.location.href='http://anotherURL.com' even if they are in different domains, from the iframe page.

Solution 3:

I assume that you want to do more in the function of your parent page; if not you can just change the url of the iframe without calling the parent of course...

As for your second question, the iframe behaves like an ebmedded page: you can browse all you want in the iframe without affecting the parent (except of course with javascript calls like the one you want to use), but browse with the parent page and you will lose teh iframe as well. Hope that was the explanation you were looking for :)

Post a Comment for "Change Url In An Iframe Using Javascript"