iframe target link to parent

Posted July 31st, 2009 in Blog by admin

My friend ask me about iframe in HTML. He has page1.aspx, page2.apsx, page3.aspx.

page1.aspx
[sourcecode lang="xhtml"]
<html>

<head>
<title>Page 1</tite>
</head>
<body name=”home”>
<iframe src=”page2.aspx”></iframe>
</body>
<html>
[/sourcecode]

page2.aspx

[sourcecode lang="html"]
<a href=”page3.aspx”>Page3</a>[/sourcecode]

He click Page3 link in iframe and page 3 is appear. He don’t want to show in iframe and he want to change in main page. So, I change link look like that

page2.aspx

[sourcecode lang="html"]
<a href=”page3.aspx” target=”_parent”>Page3</a>
[/sourcecode]

Most of the people forget about target in anchor tag. Most people just use target attribute for blank page. They forget about parent. Parent is useful for iframe. If you want to do with javascript, see following

page2.aspx (with javascript)

[sourcecode lang="html"]
<a href=”#” onclick=”parent.document.location.href=’page3.aspx’”>Page3</a> 
[/sourcecode]