window.close() and Mozilla/Netscape

S

signo

Hello to everybody,
I'm trying to make a link that closes the browser:

<a href="javascript:window.close()">CLOSE</a>

It works with IE6 but not with Mozilla and Netscape.
Does anybody knows the reason why?
Thanks.
 
V

VK

signo said:
Hello to everybody,
I'm trying to make a link that closes the browser:

<a href="javascript:window.close()">CLOSE</a>

It works with IE6 but not with Mozilla and Netscape.
Does anybody knows the reason why?

Read this newsgroup FAQ:
<http://www.jibbering.com/faq/#FAQ4_14>

If the current window has been *open via script* on the main page,
then:
<a href="noScript.html" onclick="window.close();">CLOSE</a>
will work on any decent browser.

If the current window did not appear via window.open() then the user
will be prompted first or such request will be disregarded - depending
on browser version and security settings.
 
T

Thomas 'PointedEars' Lahn

VK said:
If the current window has been *open via script* on the main page,
then:
<a href="noScript.html" onclick="window.close();">CLOSE</a>
will work on any decent browser.

However, there is exactly no use to provide a "close link" that will only
work if client-side scripting is enabled. Nothing is accomplished by
directing the user to a document that states "we are sorry that the window
could not be closed because client-side scripting is not present", and
telling him how to close the window. Maybe he do not even have one, maybe
he has a tab or something else; anyway, such a description would have to
include procedure on all conceivable UAs which is just not possible.

Such links are better to be generated _via_ scripting so that in the
unlikely event (given proper search engine optimization) someone finds the
"popup" document through a search engine, or in the more likely event that
the document is accessed through a gracefully degrading link, those users
are not bothered with virtually useless links.

<script type="text/javascript">
document.write(
'<a href="#" onclick="window.close(); return false;">CLOSE<\/a>');
</script>


PointedEars
 
G

Gérard Talbot

signo wrote :
Hello to everybody,
I'm trying to make a link that closes the browser:

Why do you need to provide a link that closes the browser? Isn't there a
close button in the titlebar to do that? Also, entirely at the disposal
of the user? Isn't that enough? A link should be used to go somewhere
(URL), not to modify the browser interface.
<a href="javascript:window.close()">CLOSE</a>

It works with IE6 but not with Mozilla and Netscape.
Does anybody knows the reason why?

Yes. The default value of dom.allow_scripts_to_close_windows is false.
In other words, by default, the browser refuses to allow script to close
windows, just like that. The user can find its way all by himself to the
titlebar or with Alt+F4 if he wants to close the window. No javascript
needed from content developer. Same thing with the opening of new
windows. Same thing with Back button. Etc... The content developer never
needs to code and to duplicate the basic and normal functionality of
browsers.

Gérard
 
S

signo

Why do you need to provide a link that closes the browser?

I'm making a CD that is containing some manuals.
The CD is starting in a "autorun way" and the interface is made in
html; anyway I gave up with the close button and I took him away.

Thanks for every suggestion.

Massimo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top