views:

461

answers:

2

Hi Webmasters.

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.

+3  A: 

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>:

<form ... target="_top">
Michal M
+1 good solution. However, it will mess up any server-side error checking if you want to re-direct the user to the original page in case of an error.
jeroen
Thank's this was the simplest solution ever:) But when I dont know it... :) It's better to ask, right:)
Spoonk
@jeroen I make a field check with javascript inside my simple .html page. I do not need a redirection in case of empty fields. I use alert :)
Spoonk
A: 

You can use javascript to access the parent. You could echo out javascript in your PHP.. so your parent page has this:

function changeURL( url ) {
    document.location = url;
}

and in your php script, you echo

<script>
   parent.changeURL('mypage2.html' );
</script>

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.

Dan Heberden