473,748 Members | 8,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

closing pop up windows

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="jscri pt">
function CloseWindow() {
self.close();
}
function printpage() {
window.print();
}
</SCRIPT>

<a href="#" onclick="printp age()">Print</a>
| <a href="#" onclick="CloseW indow()">Close Window</a>
Feb 26 '06 #1
7 1879
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

Feb 26 '06 #2
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.c om, 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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Feb 26 '06 #3
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_scrip ts_to_close_win dows
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="jscri pt">
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="printp age()">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="CloseW indow()">Close Window</a>


Gérard
--
remove blah to email me
Feb 26 '06 #4
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="jscri pt">


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

<script type="text/javascript">
[...]
--
Rob
Feb 26 '06 #5
RobG wrote:
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="jscri pt">

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

<script type="text/javascript">
[...]


I thought that "jscript" might be part of the problem.
We have 12 calendars filled with word links that generate pop-ups.
This is the code for each link:
<a href="#" onclick="Pop_De tail(3576, 58, 2, 2006)">Klondike Derby</a><br>
(yeah, it's the Scouts)... So, earlier in the page is this code:
<SCRIPT language="javas cript">
function Pop_Detail(Even tID, ScheduleID, ThisMonth, ThisYear)
{
var newWin;
newWin =window.open("e vents_popup.asp ?bmode=Detail&E ventID=" +
EventID + "&ScheduleI D=" + ScheduleID,
"kid",'resizabl e=yes,scrollbar s=yes,width=600 ,height=400,too lbar=no')
}
</SCRIPT>

Part of a massive asp/database site purchased from MS-oriented vendor.
No cross browser specifications, or testing. Once in a while, we make
a case to fix something, but got no authority. Just trying to learn.
It works, just don't close on Gecko browsers. Thanks all, rich
Feb 27 '06 #6
Rich wrote:
RobG wrote:
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="jscri pt">
The language attribute is deprecated, type is required. 'jscript'
scripts are ignored by Gecko (and likely other) browsers. Use:

<script type="text/javascript">
[...]


I thought that "jscript" might be part of the problem.
We have 12 calendars filled with word links that generate pop-ups.
This is the code for each link:
<a href="#" onclick="Pop_De tail(3576, 58, 2, 2006)">Klondike Derby</a><br>


You might find it better to add "return false" to the end of the onclick
to stop the page scrolling back to the top when pop-up links are clicked:

<a href="#"
onclick="Pop_De tail(3576, 58, 2, 2006); return false;">Klondik e
Derby</a><br>

(yeah, it's the Scouts)... So, earlier in the page is this code:
<SCRIPT language="javas cript">
The language attribute is deprecated (and has been for over 6 years),
type is required (see above).

function Pop_Detail(Even tID, ScheduleID, ThisMonth, ThisYear)
{
var newWin;
newWin =window.open("e vents_popup.asp ?bmode=Detail&E ventID=" +
EventID + "&ScheduleI D=" + ScheduleID,
"kid",'resizabl e=yes,scrollbar s=yes,width=600 ,height=400,too lbar=no')
}
</SCRIPT>
That should be OK, your problem is the script tag the pop-up which uses
'language=jscri pt'. Change it to type as suggested.

Part of a massive asp/database site purchased from MS-oriented vendor.
No cross browser specifications, or testing.
Unfortunately all to common.

Once in a while, we make
a case to fix something, but got no authority. Just trying to learn.
Good luck. :-)

It works, just don't close on Gecko browsers.


Replace the language attribute as suggested and it should.

--
Rob
Feb 27 '06 #7
Rich wrote :
I thought that "jscript" might be part of the problem.
We have 12 calendars filled with word links that generate pop-ups.
Do you really think this is the best way (popups) to implement your
calendar application?
This is the code for each link:
<a href="#" onclick="Pop_De tail(3576, 58, 2, 2006)">Klondike Derby</a><br>
(yeah, it's the Scouts)... So, earlier in the page is this code:
<SCRIPT language="javas cript">
function Pop_Detail(Even tID, ScheduleID, ThisMonth, ThisYear)
{
var newWin;
newWin =window.open("e vents_popup.asp ?bmode=Detail&E ventID=" +
EventID + "&ScheduleI D=" + ScheduleID,
"kid",'resizabl e=yes,scrollbar s=yes,width=600 ,height=400,too lbar=no')
}
</SCRIPT>


As written, the code above will have *several* problems in different
circumstances.

- for many reasons, newWin shouldn't be a local variable
- the link href shouldn't be #
- the link target should be used and identified as kid
- no detection of the presence of the window is done; no testing of the
current url is done; so your code must close any instance of newWin and
then reopen entirely all over again a new window in your
webpage/application instead

How to correct all this is explained at:

DOM:window.open
http://developer.mozilla.org/en/docs/DOM:window.open

Gérard
--
remove blah to email me
Feb 27 '06 #8

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

Similar topics

3
2323
by: ThunderMusic | last post by:
Hi, I'm trying to have a MSN Messenger like form/app closing behavior. When I click on the X button, I only want the form to disappear and when I double-click on the notify icon or right-click on it and choose Open from the context menu, I want the form to reappear. For that, I got the point covered. Even when the form is minimize, the behavior is like MSN Messenger. But one problem arose. When I close the form (the first time), it...
5
2259
by: Ron L | last post by:
I have an MDI application with a number of child windows. In each child window I am catching the Closing event and having the child window decide if it should set cancel to true. The intent here is to ensure that no child window can close while it is in a state where user entered information can be lost. I have just noticed that while the Closing event is caught if I click the X on the child window, it is not caught if I click the X on...
2
2521
by: Ron L | last post by:
I have an MDI application which opens a number of child windows, each of which could have data in a state that needs to be saved. Each child window catches its Closing event and cancels it if the user wants to save the data, but when the Application closes this event isn't thrown automatically. I added a loop to close each child window, but can't seem find how to catch the child window's cancel of the Closing event, so even if the user...
22
7578
by: alecjames1 | last post by:
I have a form which the user must complete before closing. I have disabled the window x button and use my own exit button. When selected it checks to see if the user has completed the entries otherwise it cancels the close. However, the user can still right click on the task bar and close my application. Is there any way of preventing this. Thanks Alex
6
5664
by: Al the programmer | last post by:
I want to catch the Closing event for my form. I created a test windows app using the wizard. I then create the Closing event by clicking the lightning bolt on the properties pane. The code is added to the app but my app won't compile. It generates a "Test.Form1.Closing() denotes a 'method' which is not valid in the given context" error.
6
3684
by: Barry Gast | last post by:
Hi. I have an MDI Parent form with multiple child windows. When I close the parent form, the Closing events of the children forms are not executing. Do I have to close all the child forms in the parent's closing event in order to get the closing events of the children forms to execute? Thanks. -Barry
10
4027
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms, remove the controls on each of them, and then close the form, but this code should execute only...
1
1565
by: Cedric | last post by:
Hello, I have a form that could be closed by a code keyed or selected in a combobox but when I select my code my program end up with an error (NullReferenceException) and not when I keying the code. So Does anybody have an explanation ? Here is a sample to try : START CLASS : Public Class Class1
2
3021
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...
4
2215
Fr33dan
by: Fr33dan | last post by:
Hi, I'm having trouble with a multi-threaded program crashing on a specific machine when the worker thread is not initialized at when the _FormClosing method of my main form called. Here is my on _FormClosing method: private void CycleBox_FormClosing(object sender, FormClosingEventArgs e) { // Set the boolean flags to stop cycling in worker thread. // Closing prevent dialogs from opening
0
8991
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
8830
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
9541
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
9370
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...
0
9247
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...
1
6796
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
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
2215
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.