Mark Rae [MVP] wrote:
"Gustavo Cantero" <g.*******@scientia.com.arwrote 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().