Sunday, July 6, 2008

Changing parent window's URL from IFRAME content

If you want to control parent window's URL from a child iframe, you can't use variable destination how you would use that for frames because tag <> doesn't have this property.

Also you can't change parent.document.location variable because this variable is read-only for child iframes.

To solve this problem, you need to define a javascript function at parent window and call it from iframe window. Here's an example how to change parent window's URL:


Parent window's content:

<>iframe starts here< /b >


< src="'iframe1.html'">< / iframe>




iframe ends here

< type="text/javascript">
function change_parent_url(url)
{
document.location=url;
}
< /script >

Iframe's content:

IFRAME content

< style="font-family: arial;" href="javascript:parent.change_parent_url('http://yahoo.com');">
Click here to change parent URL < /a>

0 comments: