From: Rich on
I have the following script on all pop up windows,
would like to have this work on all newer browsers if
possible. Right now it only works on MSIE & Opera.
Not sure why. Any suggestions are appreciated.
Not concerned with the print part yet. TIA Rich

<SCRIPT language="jscript">
function CloseWindow() {
self.close();
}
function printpage() {
window.print();
}
</SCRIPT>

<a href="#" onclick="printpage()">Print</a>
| <a href="#" onclick="CloseWindow()">Close Window</a>
From: Manifest Interactive on
Greetings,

You really only need to use the code window.close(); window is standard
for most DOM's so you should not have any issues with this. HOWEVER due
to most security features in standard browsers, this function, no
matter how you write it, will only work in a window that was launched
using javascript. In other words, if you open a new browser page and
access the URL that contains this script and have try to close the
window, it will do one of two things:

1. It will prompt an alert telling you that a script is trying to close
the window and it will ask if you that is OK.

2. It will ignore you script and do nothing.

The above only happen if you are in the PARENT window.

If you are launching a new window through javascript then it is assumed
you have permission to close the window and you will then be able to
close it just fine.

I hope this helps,

- Peter Schmalfeldt
Manifest Interactive

From: Randy Webb on
Manifest Interactive said the following on 2/26/2006 3:06 AM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

> Greetings,
>
> You really only need to use the code window.close(); window is standard
> for most DOM's so you should not have any issues with this. HOWEVER due
> to most security features in standard browsers, this function, no
> matter how you write it, will only work in a window that was launched
> using javascript. In other words, if you open a new browser page and
> access the URL that contains this script and have try to close the
> window, it will do one of two things:

One of 3 things.

> 1. It will prompt an alert telling you that a script is trying to close
> the window and it will ask if you that is OK.
>
> 2. It will ignore you script and do nothing.

3. It will close the window in 90% (if not more) of the browsers on the
web if you add one more line of code.

> The above only happen if you are in the PARENT window.

Huh?

> If you are launching a new window through javascript then it is assumed
> you have permission to close the window and you will then be able to
> close it just fine.

I can close it, most of the time, even if script didn't open it. At
least until IE7 is released anyway.

> I hope this helps,

It didn't, only confused because of your lack of quoting what you were
replying to.

The Unconditional Truth will explain it, search the archives for it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

From: Gérard Talbot on
Rich wrote :
> I have the following script on all pop up windows,
> would like to have this work on all newer browsers if
> possible. Right now it only works on MSIE & Opera.

I've filed a bugreport on the usage of window.close() at Microsoft and
Opera when closing a non-javascript-initiated window: Microsoft fixed it
in IE7 beta 2 and you can expect Opera to fix it too in Opera 9. There
is absolutely no reason as to why a browser should honor a script
closing a non-javascript-initiated window without the user's explicit
consent. Any window can be closed by the user with Alt+F4; any window
with a titlebar can be closed by the user by clicking the close command
icon.
Mozilla goes a bit further with
dom.allow_scripts_to_close_windows
in its user settings.

> Not sure why. Any suggestions are appreciated.

Here's one suggestion. Do not duplicate the normal browser commands, the
UI-based ones: because
- it's unneeded,
- it requires javascript support,
- it wrongly induce the users to trust websites more than their browser
commands and induce the users into not using their own browsers
- it does not induce users to get to know the commands of their own
browsers.

So:

- do not create close buttons or, worse, "close" links
- do not create go back buttons or, worse, "go back/history" links
- do not create increase/decrease font size buttons or, worse,
"increase/decrease font size" links (1)
- do not create print buttons or, worse, "print" links; with maybe only
1 exception if the link is to print a frame in a frameset...but even
there, I strongly oppose frames-based design to begin with and anyway,
the native UI for printing indicate how/which frame(s) can be printed.


(1): but you can show the users how to increase the font size. This is
what w3schools.com does at their site (see Larger text? link:
http://www.w3schools.com/largetext.htm )
and I think this is very good into helping users to get to know their
browser commands and get to know + trust their browser. Empowering the
users and letting them in control of the technology is a winning strategy.


> Not concerned with the print part yet. TIA Rich
>
> <SCRIPT language="jscript">

Language is deprecated; type is required. Best is to use
type="text/javascript"

> function CloseWindow() {
> self.close();
> }
> function printpage() {
> window.print();
> }
> </SCRIPT>
>
> <a href="#" onclick="printpage()">Print</a>

A pseudo-link which will break when javascript support is disabled or
inexistant; then it will confuse users and search indexing robots.

> | <a href="#" onclick="CloseWindow()">Close Window</a>

G?rard
--
remove blah to email me
From: RobG on
Rich wrote:
> I have the following script on all pop up windows,
> would like to have this work on all newer browsers if
> possible. Right now it only works on MSIE & Opera.
> Not sure why. Any suggestions are appreciated.
> Not concerned with the print part yet. TIA Rich
>
> <SCRIPT language="jscript">

The language attribute is deprecated, type is required. 'jscript'
scripts are ignored by Gecko (and likely other) browsers. Use:

<script type="text/javascript">


[...]


--
Rob
 |  Next  |  Last
Pages: 1 2
Prev: Checkbox value
Next: Check null or 0