473,778 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,"resi zable,scrollbar s");
setTimeout("pdf .close()", 2000);
}

Please clarify, or help... and many thanks!
Heinrich Wolf
Mar 12 '07 #1
10 3800
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,"resi zable,scrollbar s");
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.javas cript:
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,"resi zable,scrollbar s");
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.chwrot e in news:cae48$45f5 6cdb
$5************* @news.hispeed.c h:
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,"resi zable,scrollbar s");
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.chwrot e in news:cae48$45f5 6cdb
$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,"resi zable,scrollbar s");
setTimeout("pd f.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.javascrip t
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.javas cript:
@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.net wrote:
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.javas cript:
On Mar 12, 9:43 am, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
>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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
7960
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 use JS in my listing, is there a way of using JS to resize a current window, and remove the toolbars etc, so it looks like a pop-up? --
3
5197
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 image. What I would like to create is a link that can be clicked on to close the window that contains the larger image. This would make it easier for the users to close the window. I have posted the script that I use. Any help would be much...
9
3240
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 it more clear take a look at http://www.ithorizon.co.uk). I have inserted some code below to show what I currently have, but I don't have the knowledge to amend it, can somone please help. <SCRIPT LANGUAGE="JavaScript">
4
34888
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 as a new window. The original window plus the Modally opened Pop remain in a separate window. What I want to do is close the popup and return to the original window with its view state maintained. The control use to fire the popup window...
1
11583
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 http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all out). Therefore, here goes my simple "web dialog box with parent event handler fireing" solution. ...
2
3022
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 and then attempts to close the window (either via my custom 'Close' box or by clicking the close 'X' in the upper right window corner), the validation event still triggers and it tells the user that they have invalid data. Which of course means...
5
3094
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 ideas?
9
4657
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();" + "}" + "</script>";
7
5828
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 to be two techniques for earlier versions. But the window.opener='' ;window.close(); and the window.open('','_parent','') ;window.close(); techniques do not work for me. I.e., I still get confirmation message
2
6760
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 language=javascript>" js &= "var newWin = window.showModalDialog('InkommetVi.aspx" js &= "',null,"
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.