Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > close webform java script

Reply
Thread Tools

close webform java script

 
 
Paul
Guest
Posts: n/a
 
      10-07-2008
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.
 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      10-07-2008
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
>
>

 
Reply With Quote
 
 
 
 
bermanbp bermanbp is offline
Junior Member
Join Date: Oct 2008
Posts: 3
 
      10-07-2008
Try this:
Add this as an attribute to your button:

OnClientClick="return window.close()"
 
Reply With Quote
 
Ben Amada
Guest
Posts: n/a
 
      10-07-2008
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().

 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      10-08-2008
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().

 
Reply With Quote
 
Ben Amada
Guest
Posts: n/a
 
      10-08-2008
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close a TCP socket? (TCPSocket#close doesn't close it) IƱaki Baz Castillo Ruby 7 01-12-2010 01:32 PM
open webform with client script but cant close it ton ASP .Net 4 02-22-2008 12:52 AM
Close a WebForm? SetFocus in a WebForm? David Laub ASP .Net Web Controls 2 02-21-2004 04:53 AM
no code in webform using vs.net, but in webform using notepad timmso ASP .Net 1 12-12-2003 04:30 PM
Including WebForm Image Control in a Webform Table Control titof ASP .Net 0 07-24-2003 01:01 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57