tags:

views:

1976

answers:

7

I am using an IFrame, and from this IFrame I want to redirect to another page.

Please tell me how to do this without any JavaScript, ie, no window.location.

Response.Redirect shows the page in the IFrame, but I want to show page as a main page.

+3  A: 

I think there is no way to do it without JS. Browser will treat every redirect from server in the iframe. You have to 'tell' it to reload whole window using JavaScript.

Michal Dymel
A: 

has to be javascript as far as i know.

self.parent.location='http://'
runrunraygun
+14  A: 

It will be a hazard if we can manipulate other frames/window withou using client-side scripts or user-invoked actions.

Here's a list of alternatives:

Javascript options:

window.top.location.href=theLocation;
window.parent.location.href=theLocation;
window.top.location.replace(theLocation);

Non-javascript options:

<a href="theLocation" target="_top">Click here to continue</a>  
<a href="theLocation" target="_parent">Click here to continue</a>
o.k.w
+1 Nice answer :)
Madi D.
I also googled lot. But have't found any method without javascript. I use the following to to redirect (without any click because i dont have any a tag or button).ClientScript.RegisterStartupScript(GetType(), "Load", "<script type='text/javascript'>window.parent.location.href = '../CentinelError.aspx'; </script>");
Waheed
@Waheed: well, guess we can't escape the javascript ghost :p Btw, you might still want to add a link in case the user has disabled javascript.
o.k.w
Are you looking for a hyperlink?
Stevo3000
Not a hyperlink.
Waheed
A: 

I used this code.

ClientScript.RegisterStartupScript(GetType(), "Load", "<script type='text/javascript'>window.parent.location.href = '../CentinelError.aspx'; </script>");

And it works.

Waheed
That uses JavaScript.
Dolph
This is the solution I just used for a similar problem. It doesn't avoid javascript, but it does allow you perform the action in response to server actions, which is what I needed.
Eden
A: 

Well, this is really a hack, but you could define Parent-Frame as default target:

<base target="_parent">

As this will apply to all your links in the iframe, this may not be a satisfying solution ;-)

Synox
A: 

Like all others have pointed out, you can't do it without using JavaScript. However, on the server side you can emit the necessary JavaScript so that the page gets redirected to the target location as soon as it loads within the iframe.

Charles Prakash Dasari
A: 

you CAN do this without javascript, if you have access to the head block of the remote page:

<base target="_parent" />

very simple, easy, 1-line solution, if you have access to remote page head. no javascript.