37

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.

Tim S. Van Haren
  • 8,861
  • 2
  • 30
  • 34
Waheed
  • 10,086
  • 20
  • 53
  • 66

9 Answers9

75

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
  • 25,490
  • 6
  • 66
  • 63
  • 1
    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", ""); – Waheed Jan 20 '10 at 14:57
  • @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 Jan 20 '10 at 15:15
  • Are you looking for a hyperlink? – stevehipwell Jan 26 '10 at 08:35
14

I used this code.

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

And it works.

Waheed
  • 10,086
  • 20
  • 53
  • 66
  • 1
    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 Sep 02 '10 at 21:15
6

We can redirect from both server and client side when using Iframe<>

Client side response:

window.parent.location.href="http://yoursite.com"

Server side response:

Response.Write("<script type=text/javascript> window.parent.location.href ='http://yoursite.com' </script>")
5

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
  • 4,312
  • 3
  • 23
  • 32
5

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
  • 1,148
  • 2
  • 17
  • 38
0

has to be javascript as far as i know.

self.parent.location='http://'
gingerbreadboy
  • 7,386
  • 5
  • 36
  • 62
0

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
  • 4,964
  • 1
  • 27
  • 46
0
Response.Write( "<script>window.open('" + url + "','_parent');</script>" );

Answered in the below link http://forums.asp.net/t/1349064.aspx?Redirect+parent+page+from+within+Iframe

0

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.