close webform java script

Discussion in 'ASP .Net' started by Paul, Oct 7, 2008.

  1. Paul

    Paul Guest

    I am looking for a java script to close a web form that I can attatch to a
    button click event. I am using vs2005, c#.
    Thanks
    --
    Paul G
    Software engineer.
    Paul, Oct 7, 2008
    #1
    1. Advertising

  2. Paul

    Paul Guest

    Thanks for the responses, do I just attatch this to the onclick event?
    --
    Paul G
    Software engineer.


    "Mark Rae [MVP]" wrote:

    > "Gustavo Cantero" <> wrote in message
    > news:7A0F0A1B77EE4A3F932D1D235D10FF6F@CATALINA...
    >
    > [top-posting corrected]
    >
    > >> I am looking for a java script to close a web form that I can attatch to
    > >> a
    > >> button click event. I am using vs2005, c#.

    > >
    > > The script "window.close()" close the window in the browser. Is this
    > > that you need?

    >
    > That will generate a message asking the user to confirm that they want to
    > close the window, and you have omitted the final semi-colon.
    >
    > The correct JavaScript is:
    >
    > "window.opener=null;window.close();"
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
    Paul, Oct 7, 2008
    #2
    1. Advertising

  3. Paul

    bermanbp

    Joined:
    Oct 7, 2008
    Messages:
    3
    Try this:
    Add this as an attribute to your button:

    OnClientClick="return window.close()"
    bermanbp, Oct 7, 2008
    #3
  4. Paul

    Ben Amada Guest

    Mark Rae [MVP] wrote:

    > "Gustavo Cantero" <> wrote in message
    > news:7A0F0A1B77EE4A3F932D1D235D10FF6F@CATALINA...
    >
    >>> I am looking for a java script to close a web form that I can attatch
    >>> to a button click event. I am using vs2005, c#.

    >>
    >> The script "window.close()" close the window in the browser. Is this
    >> that you need?

    >
    > That will generate a message asking the user to confirm that they want
    > to close the window, and you have omitted the final semi-colon.
    >
    > The correct JavaScript is:
    >
    > "window.opener=null;window.close();"


    That only appears to be the case with IE6.

    In IE7, setting opener to null doesn't appear to make a difference. There
    is a difference between closing a window that was opened by script versus
    closing a window that was not opened by script. You're prompted with a
    confirmation if closing a window that was _not_ opened by JavaScript. If
    the window was opened by JavaScript, you're not prompted with a confirmation
    (it just closes). Setting window.opener to null doesn't change this.

    In Firefox, if you try to close a window that was not opened by JavaScript,
    it doesn't close and you get the message "Warning: Scripts may not close
    windows that were not opened by script." in the error console. If you close
    a window that was opened by JavaScript, you're not prompted with a
    confirmation (it just closes). This is true regardless of setting
    window.opener to null.

    In Safari 3.1, setting opener to null makes no difference. Windows opened
    by script always close without a confirmation, and windows not opened by
    script will not close with window.close().
    Ben Amada, Oct 8, 2008
    #4
  5. Paul

    bruce barker Guest

    setting opener to null was a trick that works due a (minor) security bug
    with ie 6.0 (opener should be read only). no properly coded browser will
    allow javascript to close a main (non popup) window, only windows that
    were opened with javascript (and thus have an opener defined) will
    respond to window.close().

    -- bruce (sqlwork.com)

    Ben Amada wrote:
    > Mark Rae [MVP] wrote:
    >
    >> "Gustavo Cantero" <> wrote in message
    >> news:7A0F0A1B77EE4A3F932D1D235D10FF6F@CATALINA...
    >>
    >>>> I am looking for a java script to close a web form that I can attatch
    >>>> to a button click event. I am using vs2005, c#.
    >>>
    >>> The script "window.close()" close the window in the browser. Is this
    >>> that you need?

    >>
    >> That will generate a message asking the user to confirm that they want
    >> to close the window, and you have omitted the final semi-colon.
    >>
    >> The correct JavaScript is:
    >>
    >> "window.opener=null;window.close();"

    >
    > That only appears to be the case with IE6.
    >
    > In IE7, setting opener to null doesn't appear to make a difference.
    > There is a difference between closing a window that was opened by script
    > versus closing a window that was not opened by script. You're prompted
    > with a confirmation if closing a window that was _not_ opened by
    > JavaScript. If the window was opened by JavaScript, you're not prompted
    > with a confirmation (it just closes). Setting window.opener to null
    > doesn't change this.
    >
    > In Firefox, if you try to close a window that was not opened by
    > JavaScript, it doesn't close and you get the message "Warning: Scripts
    > may not close windows that were not opened by script." in the error
    > console. If you close a window that was opened by JavaScript, you're
    > not prompted with a confirmation (it just closes). This is true
    > regardless of setting window.opener to null.
    >
    > In Safari 3.1, setting opener to null makes no difference. Windows
    > opened by script always close without a confirmation, and windows not
    > opened by script will not close with window.close().
    bruce barker, Oct 8, 2008
    #5
  6. Paul

    Ben Amada Guest

    bruce barker wrote:

    > setting opener to null was a trick that works due a (minor) security bug
    > with ie 6.0 (opener should be read only). no properly coded browser will
    > allow javascript to close a main (non popup) window, only windows that
    > were opened with javascript (and thus have an opener defined) will
    > respond to window.close().


    Aaah ... I wasn't aware of this issue with IE6. Another item on my "go away
    IE6" list :)
    Ben Amada, Oct 8, 2008
    #6
    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. titof
    Replies:
    0
    Views:
    490
    titof
    Jul 24, 2003
  2. timmso
    Replies:
    1
    Views:
    470
    Alex Papadimoulis
    Dec 12, 2003
  3. ton
    Replies:
    4
    Views:
    1,321
    siccolo
    Feb 22, 2008
  4. David Laub

    Close a WebForm? SetFocus in a WebForm?

    David Laub, Feb 18, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    323
    Alvin Bruney [MVP]
    Feb 21, 2004
  5. Iñaki Baz Castillo
    Replies:
    7
    Views:
    823
    Iñaki Baz Castillo
    Jan 12, 2010
Loading...

Share This Page