473,396 Members | 1,748 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,396 software developers and data experts.

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

<a href="#" onclick="printpage()">Print</a>
| <a href="#" onclick="CloseWindow()">Close Window</a>
Feb 26 '06 #1
7 1851
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.com, 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.javascript 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_scripts_to_close_windows
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="jscript">
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="printpage()">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="CloseWindow()">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="jscript">


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="jscript">

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_Detail(3576, 58, 2, 2006)">Klondike Derby</a><br>
(yeah, it's the Scouts)... So, earlier in the page is this code:
<SCRIPT language="javascript">
function Pop_Detail(EventID, ScheduleID, ThisMonth, ThisYear)
{
var newWin;
newWin =window.open("events_popup.asp?bmode=Detail&EventI D=" +
EventID + "&ScheduleID=" + ScheduleID,
"kid",'resizable=yes,scrollbars=yes,width=600,heig ht=400,toolbar=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="jscript">
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_Detail(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_Detail(3576, 58, 2, 2006); return false;">Klondike
Derby</a><br>

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

function Pop_Detail(EventID, ScheduleID, ThisMonth, ThisYear)
{
var newWin;
newWin =window.open("events_popup.asp?bmode=Detail&EventI D=" +
EventID + "&ScheduleID=" + ScheduleID,
"kid",'resizable=yes,scrollbars=yes,width=600,heig ht=400,toolbar=no')
}
</SCRIPT>
That should be OK, your problem is the script tag the pop-up which uses
'language=jscript'. 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_Detail(3576, 58, 2, 2006)">Klondike Derby</a><br>
(yeah, it's the Scouts)... So, earlier in the page is this code:
<SCRIPT language="javascript">
function Pop_Detail(EventID, ScheduleID, ThisMonth, ThisYear)
{
var newWin;
newWin =window.open("events_popup.asp?bmode=Detail&EventI D=" +
EventID + "&ScheduleID=" + ScheduleID,
"kid",'resizable=yes,scrollbars=yes,width=600,heig ht=400,toolbar=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
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...
5
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...
2
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...
22
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...
6
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...
6
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...
10
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...
1
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...
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...
4
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.