window.close()

H

Heinrich Wolf

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
 
R

Richard Cornford

Heinrich said:
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.
 
E

Evertjan.

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>
 
L

Lee

NO said:
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.


--
 
H

Heinrich Wolf

Lee said:
...
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
 
E

Evertjan.

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.
 
H

Heinrich Wolf

Evertjan. said:
...
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
 
S

scripts.contact

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);
};
 
E

Evertjan.

wrote on 13 mrt 2007 in comp.lang.javascript:
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?
 
A

ASM

Evertjan. a écrit :
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' ?
 

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,776
Messages
2,569,603
Members
45,186
Latest member
vinaykumar_nevatia

Latest Threads

Top