I have a simple form which is inside IFRAME. When user click on SUBMIT, it redirects to a specific page on my server. The function I use for the redirect is
header ('Location: mypage2.html');
exit ();
But I want the new page to open in _top location, not inside the same IFRAME that I use. How can I tell the browser to open the new page in _top not inside the IFRAME? Thanks in advance.
we can use javascript like this :
You can use javascript to access the parent. You could echo out javascript in your PHP.. so your parent page has this:
and in your php script, you echo
The reason you can't call parent.document.location is because it's read only - you have to have a function available on the parent to do it.
You can either link to the page using
<a href="pagename.php?Break=Y">Break Out</a>
or use codeYou then use the following code in the header of the page with
A simple way directly in PHP to redirect the parent page rather than the iframe:
The
die;
isn't necessarily necessary, but it is good "just in case" to prevent the script from continuing any further, for example, if javascript is disabled in the user's browser.You are not able to achieve the desired effect in PHP. This is something you'd have to do from JavaScript or add
target
attribute to<form>
:The best and simplest thing to do is to use the form target element
either of the target parameters works fine