Close button on web form

Discussion in 'ASP .Net' started by Ron Lautmann, Jun 11, 2004.

  1. Ron Lautmann

    Ron Lautmann Guest

    I want to close a browser window so I created a Close button that does this:

    private void Button1_Click(object sender, System.EventArgs e)
    {
    RegisterClientScriptBlock("GetData","<Script>close()</Script>");
    }

    But when this runs the browser puts up a dialog box saying: "The web page
    you are viewing is trying to close the window, od you want to close this
    window?"

    Is there a way to close a browser window without this dialog box?
     
    Ron Lautmann, Jun 11, 2004
    #1
    1. Advertising

  2. HI Ron,

    No, there is no way of doing this. The only windows you can close with any
    notification are the windows that your browser create.

    Cheers,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation

    "Ron Lautmann" <> wrote in message
    news:...
    > I want to close a browser window so I created a Close button that does

    this:
    >
    > private void Button1_Click(object sender, System.EventArgs e)
    > {
    > RegisterClientScriptBlock("GetData","<Script>close()</Script>");
    > }
    >
    > But when this runs the browser puts up a dialog box saying: "The web page
    > you are viewing is trying to close the window, od you want to close this
    > window?"
    >
    > Is there a way to close a browser window without this dialog box?
    >
    >
     
    Ignacio Machin \( .NET/ C# MVP \), Jun 11, 2004
    #2
    1. Advertising

  3. > No, there is no way of doing this. The only windows you can close with
    any
    > notification are the windows that your browser create.


    Not true! The window.close() method checks to see if the opener property of
    the window is null (meaning that it was not spawned by another browser
    window). If you set the opener property to the window itself, it closes
    without a prompt:

    window.opener = self;
    window.close();

    Try it!

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
    in message news:...
    > HI Ron,
    >
    > No, there is no way of doing this. The only windows you can close with

    any
    > notification are the windows that your browser create.
    >
    > Cheers,
    >
    > --
    > Ignacio Machin,
    > ignacio.machin AT dot.state.fl.us
    > Florida Department Of Transportation
    >
    > "Ron Lautmann" <> wrote in message
    > news:...
    > > I want to close a browser window so I created a Close button that does

    > this:
    > >
    > > private void Button1_Click(object sender, System.EventArgs e)
    > > {
    > > RegisterClientScriptBlock("GetData","<Script>close()</Script>");
    > > }
    > >
    > > But when this runs the browser puts up a dialog box saying: "The web

    page
    > > you are viewing is trying to close the window, od you want to close this
    > > window?"
    > >
    > > Is there a way to close a browser window without this dialog box?
    > >
    > >

    >
    >
     
    Kevin Spencer, Jun 11, 2004
    #3
  4. Ron Lautmann

    Ron Lautmann Guest

    That solution works well! Thanks for the info.

    Ron Lautmann


    "Kevin Spencer" <> wrote in message
    news:...
    > > No, there is no way of doing this. The only windows you can close with

    > any
    > > notification are the windows that your browser create.

    >
    > Not true! The window.close() method checks to see if the opener property

    of
    > the window is null (meaning that it was not spawned by another browser
    > window). If you set the opener property to the window itself, it closes
    > without a prompt:
    >
    > window.opener = self;
    > window.close();
    >
    > Try it!
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Big things are made up
    > of lots of little things.
    >
    > "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>

    wrote
    > in message news:...
    > > HI Ron,
    > >
    > > No, there is no way of doing this. The only windows you can close with

    > any
    > > notification are the windows that your browser create.
    > >
    > > Cheers,
    > >
    > > --
    > > Ignacio Machin,
    > > ignacio.machin AT dot.state.fl.us
    > > Florida Department Of Transportation
    > >
    > > "Ron Lautmann" <> wrote in message
    > > news:...
    > > > I want to close a browser window so I created a Close button that does

    > > this:
    > > >
    > > > private void Button1_Click(object sender, System.EventArgs e)
    > > > {
    > > > RegisterClientScriptBlock("GetData","<Script>close()</Script>");
    > > > }
    > > >
    > > > But when this runs the browser puts up a dialog box saying: "The web

    > page
    > > > you are viewing is trying to close the window, od you want to close

    this
    > > > window?"
    > > >
    > > > Is there a way to close a browser window without this dialog box?
    > > >
    > > >

    > >
    > >

    >
    >
     
    Ron Lautmann, Jun 11, 2004
    #4
  5. Hi Kevin,

    Thanks for the tips, I had never imagined that, I think this is something
    MS needs to change, it allow a rogue page to close my browser without a
    warning.

    I had always thought it was not possible

    Thank again,


    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation

    "Kevin Spencer" <> wrote in message
    news:...
    > > No, there is no way of doing this. The only windows you can close with

    > any
    > > notification are the windows that your browser create.

    >
    > Not true! The window.close() method checks to see if the opener property

    of
    > the window is null (meaning that it was not spawned by another browser
    > window). If you set the opener property to the window itself, it closes
    > without a prompt:
    >
    > window.opener = self;
    > window.close();
    >
    > Try it!
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Big things are made up
    > of lots of little things.
    >
    > "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>

    wrote
    > in message news:...
    > > HI Ron,
    > >
    > > No, there is no way of doing this. The only windows you can close with

    > any
    > > notification are the windows that your browser create.
    > >
    > > Cheers,
    > >
    > > --
    > > Ignacio Machin,
    > > ignacio.machin AT dot.state.fl.us
    > > Florida Department Of Transportation
    > >
    > > "Ron Lautmann" <> wrote in message
    > > news:...
    > > > I want to close a browser window so I created a Close button that does

    > > this:
    > > >
    > > > private void Button1_Click(object sender, System.EventArgs e)
    > > > {
    > > > RegisterClientScriptBlock("GetData","<Script>close()</Script>");
    > > > }
    > > >
    > > > But when this runs the browser puts up a dialog box saying: "The web

    > page
    > > > you are viewing is trying to close the window, od you want to close

    this
    > > > window?"
    > > >
    > > > Is there a way to close a browser window without this dialog box?
    > > >
    > > >

    > >
    > >

    >
    >
     
    Ignacio Machin \( .NET/ C# MVP \), Jun 14, 2004
    #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. Denon
    Replies:
    1
    Views:
    598
    Saravana [MVP]
    Nov 14, 2003
  2. Daniel Albisser
    Replies:
    1
    Views:
    1,151
    GaryM
    Apr 7, 2004
  3. Neil
    Replies:
    6
    Views:
    39,796
    atilio123321
    Sep 2, 2011
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    940
    Iñaki Baz Castillo
    Jan 12, 2010
  5. Replies:
    5
    Views:
    334
Loading...

Share This Page