how to redirect parent page from iframe page_load?

S

Sheryl Landon

Hi, I'm having a similar issue as the poster Mike whose message I copied
below... I have a page with an iframe... when I discover that the session
state is no longer valid in the page inside the iframe, I want to redirect
the parent page to a login page. Can anyone help me?

Thanks,
Sheryl


How can an IFrame's aspx page force a server-side redirect on its parent
page? Typically, an IFrame's client-side javascript specifies '_top' to
change the parent page...
window.open('default.aspx?SMID=18', '_top', '', false);
 
R

Robbe Morris [C# MVP]

Stick this at the top of all your non-iframe pages and
call it in the body onload event.

If your page in an iframe attempts to redirect to one of
the non-frame pages, it will break out of the iframe.

function TimeOutRedirect()
{

try
{
if (self.parent.frames.length != 0)
self.parent.location=document.location;
}
catch (Exception) {}

}

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx
 
S

Sheryl Landon

Hey, that's way cool! the first thing I've seen that worked in my
situation! And I've tried quite a few "solutions" out there! Thanks!
 
Joined
Aug 5, 2010
Messages
1
Reaction score
0
Hello:

I was wondering if this solution would also work in Firefox 3.6? I realize that it's been 5 years since the above solution was posted. It works in IE 7.

Ray G.
 
Joined
Feb 27, 2012
Messages
1
Reaction score
0
Thank you!

Thank you! It worked for me on Chrome, Firefox and IE.





Robbe Morris [C# MVP];453647 said:
Stick this at the top of all your non-iframe pages and
call it in the body onload event.

If your page in an iframe attempts to redirect to one of
the non-frame pages, it will break out of the iframe.

function TimeOutRedirect()
{

try
{
if (self.parent.frames.length != 0)
self.parent.location=document.location;
}
catch (Exception) {}

}

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx



"Sheryl Landon" <[email protected]> wrote in message
news:[email protected]...
> Hi, I'm having a similar issue as the poster Mike whose message I copied
> below... I have a page with an iframe... when I discover that the session
> state is no longer valid in the page inside the iframe, I want to redirect
> the parent page to a login page. Can anyone help me?
>
> Thanks,
> Sheryl
>
>
> "MLibby" <[email protected]> wrote in message
> news:<[email protected]>...
>
>> How can an IFrame's aspx page force a server-side redirect on its parent
>> page? Typically, an IFrame's client-side javascript specifies '_top' to
>> change the parent page...

>
>> window.open('default.aspx?SMID=18', '_top', '', false);

>
>> > However, the server-side Redirect doesn't include '_top'. I tried to
>> > write the following from server-side code hoping it would execute
>> > immediatly at the client but it won't fire, I'm not sure why:
>> > Response.Write("<script
>> > language=javascript>window.open('default.aspx?SMID=18', '_top', '',
>> > false);</script>");

>
>> Please let me know if you have any ideas and thanks in advance for any
>> help,

>
>> Mike

>
>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top