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

window.close()

P: n/a
Hi all,

Please direct me to a current treatise of window.close().

My info is that a window can be closed provided it has
been opened by the same script or functions within the
same document.

And this is as far as I've got, but no success:

function window(url) {
var pdf = window.open (url,null,"resizable,scrollbars");
setTimeout("pdf.close()", 2000);
}

Please clarify, or help... and many thanks!
Heinrich Wolf
Mar 12 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Heinrich Wolf wrote:
Please direct me to a current treatise of window.close().

My info is that a window can be closed provided it has
been opened by the same script or functions within the
same document.
Generally it would not matter that the code that attempted to close a
window was in the same script or function or not. If the window was not
opened with a script it should not be possible to close it with a script.

But the biggest issue with opening new windows is that pop-up blocking
may prevent them opening at all, so the ability to close them or not is a
relatively insignificant side issue in terms of designing for the
Internet.
And this is as far as I've got, but no success:
Making "no success" the extent of your explanation of what your code
actually does will tend not to get you any useful help.
function window(url) {
var pdf = window.open (url,null,"resizable,scrollbars");
setTimeout("pdf.close()", 2000);
}
The string values provided as the first argument to - setTimeout - are
evaluated in the global execution context, and your - pdf - is declared
as a local variable, and so probably unknown in the global execution
context.

Richard.

Mar 12 '07 #2

P: n/a
Heinrich Wolf wrote on 12 mrt 2007 in comp.lang.javascript:
Please direct me to a current treatise of window.close().

My info is that a window can be closed provided it has
been opened by the same script or functions within the
same document.

And this is as far as I've got, but no success:

function window(url) {
var pdf = window.open (url,null,"resizable,scrollbars");
setTimeout("pdf.close()", 2000);
}
1
Do not use the word window,
as this is reserved for your subsequent use.

2
pdf is not globally defined,
so not available to the timeout execution

3
Two seconds is a short time
to set up a window far inough to remove it again

try:

<script type='text/javascript'>
var w;

function doit(url) {
w = window.open(url);
setTimeout( 'w.close()', 15000);
};

</script>

<button onclick='doit("http://cnn.com/")'>
cnn</button>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 12 '07 #3

P: n/a
Heinrich Wolf <XX************@hispeed.chwrote in news:cae48$45f56cdb
$5*************@news.hispeed.ch:
Hi all,

Please direct me to a current treatise of window.close().

My info is that a window can be closed provided it has
been opened by the same script or functions within the
same document.

And this is as far as I've got, but no success:

function window(url) {
var pdf = window.open (url,null,"resizable,scrollbars");
setTimeout("pdf.close()", 2000);
}

Please clarify, or help... and many thanks!
Heinrich Wolf
1. "window" is a reserved word. Use a different variable, such as
myNewWindow.

2. The syntax for using setTimeout is:

var junk = setTimeout("pdf.close()", 2000);
Mar 12 '07 #4

P: n/a
Lee
NO said:
>
Heinrich Wolf <XX************@hispeed.chwrote in news:cae48$45f56cdb
$5*************@news.hispeed.ch:
>Hi all,

Please direct me to a current treatise of window.close().

My info is that a window can be closed provided it has
been opened by the same script or functions within the
same document.

And this is as far as I've got, but no success:

function window(url) {
var pdf = window.open (url,null,"resizable,scrollbars");
setTimeout("pdf.close()", 2000);
}

Please clarify, or help... and many thanks!
Heinrich Wolf

1. "window" is a reserved word. Use a different variable, such as
myNewWindow.

2. The syntax for using setTimeout is:

var junk = setTimeout("pdf.close()", 2000);
The OP's syntax is fine. If you're never going to use the variable
"junk", you simply discard the returned value by not assigning it to
a variable.
--

Mar 12 '07 #5

P: n/a
Lee wrote:
...
The OP's syntax is fine. If you're never going to use the variable
"junk", you simply discard the returned value by not assigning it to
a variable.
@Richard
"no success" - yes, window opens, but never closes, so (my)
pop-up blocker is not involved. Have to verify once it works here.

@Evertjan, Jim
- window() is translation issue - original here is German fenster()
- pdf now is global variable, but no improvement
- time not yet relevant, since pertaining pdf's are local

In the meantime I exchanged posts in the German d.c.l.javascript
NG too, with "no success" again. But then we found out that may be
the pdf reader Foxit I prefer is the culprit. The script as is works
with Foxit and any local *.htm and any http://.., but not with *.pdf.

Looks like I have to revert to the Adobe Reader.
I'll find out and let you know.

Thanks and regards
Heinrich Wolf
Mar 12 '07 #6

P: n/a
Heinrich Wolf wrote on 12 mrt 2007 in comp.lang.javascript:
@Evertjan, Jim
- window() is translation issue - original here is German fenster()
The danger of code translation ;-(
- pdf now is global variable, but no improvement
Did you try my CNN code, it worked fine overhere!!
- time not yet relevant, since pertaining pdf's are local
You cannot know that for certain, till you have a working example.

pdf's ??

It could be that a pdf window cannot be closed by the originating
javascript in some browser/reader combinations.

First try an html page.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 12 '07 #7

P: n/a
Evertjan. schrieb:
>...
Did you try my CNN code, it worked fine overhere!!
As I said proviously, any http://... opens correctly -
in Firefox or IE7 that is, and closes after 15secs.
...
pdf's ??
Meaning pdf-files, geared to Foxit or Adobe Reader.

In the meantime, I installed the monster Adobe Reader,
but didn't get clear with it and sincerely hope to be
able to revert to Foxit.

I sent a support request to the Foxit people and wait
for an answer - and hopefully solution.

Heinrich Wolf
Mar 12 '07 #8

P: n/a
On Mar 12, 9:43 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
pdf is not globally defined,
so not available to the timeout execution

var w;
function doit(url) {
w = window.open(url);
setTimeout( 'w.close()', 15000);

};
why are you using a string as the first parameter and defining the w
globally. what is wrong with this -

function doit(url) {
var w = window.open(url);
setTimeout( function(){ w.close() }, 15000);
};

Mar 13 '07 #9

P: n/a
wrote on 13 mrt 2007 in comp.lang.javascript:
On Mar 12, 9:43 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>pdf is not globally defined,
so not available to the timeout execution

var w;
function doit(url) {
w = window.open(url);
setTimeout( 'w.close()', 15000);

};

why are you using a string as the first parameter globally.
Because some browsers are not able to do without it.
and defining the w
because, as I said, in the standard way of using setTimeout,
a local scoped variable w will not be available anymore.

what is wrong with this -

function doit(url) {
var w = window.open(url);
setTimeout( function(){ w.close() }, 15000);
};
Nothing, should it be "wrong" in your view?

Did you test it cross browser?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 13 '07 #10

P: n/a
ASM
Evertjan. a écrit :
> what is wrong with this -

function doit(url) {
var w = window.open(url);
setTimeout( function(){ w.close() }, 15000);
};

Nothing, should it be "wrong" in your view?

Did you test it cross browser?
Personally, no I can't : no IE ...

Will or will not IE close the window 'w' ?

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Mar 13 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.