Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response.Redirect() in iFrame, redirect parent window

I know this isn't possible, but what is the best alternative for wanting to do Response.Redirect from an iFrame, to redirect the parent page?

like image 808
Curtis Avatar asked Sep 05 '11 11:09

Curtis


People also ask

Can we redirect in iframe?

Redirect the page containing your iframe embed Modern browsers will prevent an iframe from changing the location of its parent page for security reasons. Your iframe embed code and JavaScript code will need to be modified to allow this behavior.

How do I use response redirect?

Response. Redirect sends an HTTP request to the browser, then the browser sends that request to the web server, then the web server delivers a response to the web browser. For example, suppose you are on the web page "UserRegister. aspx" page and it has a button that redirects you to the "UserDetail.

How do I stop iframe from redirecting top level windows?

You can set sandbox="" , which prevents the iframe from redirecting. That being said it won't redirect the iframe either. You will lose the click essentially.


1 Answers

You can not do this using ASP.NET. ASP.NET on server side can redirect incoming request and can't know about a parent frame.

But if you want to redirect parent frame on some server side condition you can call JavaScript from server like this:

protected void Page_Load(object sender, EventArgs e) {
   ClientScriptManager.RegisterClientScriptBlock(this.GetType(), 
       "RedirectScript", "window.parent.location = 'http://yoursite.com'", true);
}

And of course you can use simple JavaScript window.parent.location = 'http://yoursite.com' on client side.

like image 59
Baidaly Avatar answered Oct 29 '22 14:10

Baidaly