473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

window.close()

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
10 3750
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Nigel Mercier ® | last post by:
I'm just starting to learn JavaScript, so far I like it! I want to add some JS to my Ebay listings, to manually open a pop-up window. It works OK, but the JS gets rejected by Ebay. If I can't...
3
by: Steve | last post by:
Hi, I have a nice little script that works well displaying images on my website. It's a script where if you clik a thumbnail image a pop up window opens that contains a larger version of the same...
9
by: Graham | last post by:
What I currently have is a page that opens another browser at 800x600, once that is loaded I would like to close the orginal page down while keeping the page that it has just opened open (To make...
4
by: GrantS | last post by:
I am having a problem closing a popup window opened modally. When I try to close the window (when the user hits save button and the data has been processed), the Popup window opens as a full screen...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
2
by: Tom | last post by:
How is the best way to avoid validation when closing a window? For instance, I have a Windows Forms window which has a validation event for a text box. However, if one enters invalid data in then...
5
by: lindanr | last post by:
In ASP.NET 2005 I have an onblur="window.close()" javascript event in the <body> tag. When I click on the window's scrollbar, the window closes. The same code works fine in ASP.NET 2003. Any...
9
by: Stan B | last post by:
I create a popup window by calling window.showModalDialog Popup window has Ok button with this code attached: === string Script = "<script language=JavaScript>" + "{" + "window.close();" +...
7
by: Toccoa | last post by:
After considerable googling - I mean searching with Google(r) - I could not find javascript on a button or <a href=... to close a window in the latest versions of IE and FireFox. There seemed...
2
by: kurt sune | last post by:
Hello, I have a weird problem, I hope someone can explain this for me. I have a webpage using masterpage. In it I create a popup window using this code: Dim js As String = "<script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.