how to redirect parent page from iframe page_load?

Discussion in 'ASP .Net' started by Sheryl Landon, Apr 28, 2005.

  1. 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" <> wrote in message
    news:<>...

    > 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
    Sheryl Landon, Apr 28, 2005
    #1
    1. Advertising

  2. frame buster code

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:<>...
    >
    >> 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

    >
    >
    Robbe Morris [C# MVP], Apr 28, 2005
    #2
    1. Advertising

  3. Re: frame buster code

    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!

    "Robbe Morris [C# MVP]" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:...
    >> 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" <> wrote in message
    >> news:<>...
    >>
    >>> 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

    >>
    >>

    >
    >
    Sheryl Landon, Apr 28, 2005
    #3
  4. Sheryl Landon

    raygberg

    Joined:
    Aug 5, 2010
    Messages:
    1
    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.
    raygberg, Aug 5, 2010
    #4
  5. Sheryl Landon

    sateswar

    Joined:
    Feb 27, 2012
    Messages:
    1
    Thank you!

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





    sateswar, Feb 27, 2012
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeronimo Bertran

    Refresh Parent from iframe Page_Load

    Jeronimo Bertran, Jan 17, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    41,086
    aghasoft
    Jul 29, 2011
  2. =?Utf-8?B?TUxpYmJ5?=

    Redirect an IFrame's Parent Page: Server-Side Code

    =?Utf-8?B?TUxpYmJ5?=, Mar 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    12,600
    Sheryl Landon
    Apr 28, 2005
  3. Replies:
    0
    Views:
    680
  4. Replies:
    0
    Views:
    136
  5. PD
    Replies:
    6
    Views:
    710
Loading...

Share This Page