By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,939 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,939 IT Pros & Developers. It's quick & easy.

window.close() and Mozilla/Netscape

P: n/a
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.

Nov 24 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
VK

signo wrote:
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.

Nov 24 '05 #2

P: n/a
VK wrote:
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
Nov 24 '05 #3

P: n/a
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
--
remove blah to email me
Nov 24 '05 #4

P: n/a
>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

Nov 24 '05 #5

P: n/a
On 2005-11-24, signo <ma**************@libero.it> wrote:
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.


security.


--

Bye.
Jasen
Nov 26 '05 #6

P: 1
In Mozilla by default the "dom.allow_scripts_to_close_windows" value which controls the Java Script close window is set to "false". In order to fix this issue change this value to "true"

1. Location of the File:
C:\Program Files\Mozilla Firefox\greprefs\all.js

change "dom.allow_scripts_to_close_windows" from "false" to "true"

Example:
Default value
pref("dom.allow_scripts_to_close_windows", false);

Change it to
pref("dom.allow_scripts_to_close_windows", true);

2.Close Mozilla browser

3.Try accessing HTML page which has window.close() code snippet... :)
Mar 8 '06 #7

P: 1
hope this script will help u to close the window.

The first step is to fool the browser into thinking that it was opened with a script…

window.open('','_parent','');

This opens a new page, (non-existent), into a target frame/window, (_parent which of course is the window in which the script is executed, so replacing itself), and defines parameters such as window size etc, (in this case none are defined as none are needed). Now that the browser thinks a script opened a page we can quickly close it in the standard way…

window.close();

And there you have it - I told you it was simple! In case you didn’t follow that, here is the complete solution in two easy steps:

1. Copy/paste the following code to the head of your page…

<script language="javascript" type="text/javascript">

function closeWindow() {

window.open('','_parent','');

window.close();

}

</script>

2. Set your link like this:

<a href="javascript:closeWindow();">Close Window</a>

And there you have it - A problem that it seemed, (according to my trying to find a solution before coming up with this one anyway), to have baffled everyone else.
May 22 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.