开发者

Redirect the parent page from IFrame

开发者 https://www.devze.com 2022-12-17 22:21 出处:网络
I am using an IFrame, and from t开发者_运维百科his IFrame I want to redirect to another page.

I am using an IFrame, and from t开发者_运维百科his 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.


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>


I used this code.

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

And it works.


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>")


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.


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 ;-)


has to be javascript as far as i know.

self.parent.location='http://'


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.


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号