Click to See Complete Forum and Search --> : window.close() question:
sydmil
12-11-2003, 08:49 AM
Using the command:
<body onLoad=" window.close()">
will result in a response warning the user that "the web page you are viewing is trying to close the window".
How can you alter it, so that when the user relies NO, it will not close the window, but will re-direct the user to a different ULR.
Anyone? Thanks for any suggestions!
gil davis
12-11-2003, 08:57 AM
Browsers have built-in security that will not let you close a window that you did not open using JavaScript.
You cannot alter the action.
You can tell that the user said "no" by the fact that the page is still active. If you want to redirect to a different URL, just do that. IMHO, there isn't any valid reason to close the window if you did not open it.
Aunecah
12-11-2003, 09:07 AM
How about adding a function instead of using the window.close()? Ask the user for confirmation - something like
if(confirm("The window you're browsing is trying to close itself. Go ahead with the action?"))
window.close();
else
window.location.href=[the location goes here];
Aunecah
sydmil
12-11-2003, 09:15 AM
Aunecah, Gil, thanks for your replies!
What I'm trying to achieve is, when a user enters a certain page it will automatically attempt to close that page for him, but I'm giving him an option of not closing by redirecting him to another URL. As it is, answering NO to the window.close() prompt will leave him at the same URL where he entered, which I don't want.