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

De-activating windows using Javascript

How do I deactivate a window using Javascript. For example if I have
a window that opens up another window, how do I prevent the user from
clicking (doing anything) in the original window until the new window
has been closed. Any insight will help. Thank you very much in
advanced.
Jul 20 '05 #1
3 11577
Ivo
"Maria Bitsku" <mi************@hotmail.com> wrote in message
news:90**************************@posting.google.c om...
How do I deactivate a window using Javascript. For example if I have
a window that opens up another window, how do I prevent the user from
clicking (doing anything) in the original window until the new window
has been closed. Any insight will help. Thank you very much in
advanced.


onblur="self.focus()" in the popup will bring it to the front whenever
another browser window is clicked. But user can still go to another program.
Ivo
Jul 20 '05 #2

"Maria Bitsku" <mi************@hotmail.com> wrote in message
news:90**************************@posting.google.c om...
How do I deactivate a window using Javascript. For example if I have
a window that opens up another window, how do I prevent the user from
clicking (doing anything) in the original window until the new window
has been closed. Any insight will help. Thank you very much in
advanced.


Hi there,

The kind of window you refer to is usually called a "modal window" or "modal
dialog".

Using self.focus() in the popup window (as suggested by Ivo) is a possible
solution but not a very good one as:

1. It will not work very well with some browsers.

2. The popup window becomes obtrusive for other (non-browser or irrelevant
browser) windows as well.

3. You have to put this code in the popup window itself.

Trying to assign a handler function to the onblur event of the newly open
window (from the opener window) is still plagued with problems number 1 and
2.
Other solutions:
---------------

* In IE there is showModalDialog() which creates a perfect modal dialog for
you. There may be something similar in some other browsers but it is fair to
say that this kind of solution would not cover a lot of browser real estate.

* You can use something like the following which I just put together and
have not tested with many browsers but please tell us of the results if you
test it yourself. It should however cover a lot of browsers. Basically it
tries to block all access to the opener window and puts focus on the popup
instead:

<script>

//Should be at least mozilla and ie (maybe 4.0+) compatible.
//You can try other event combos.
//With Mozilla you can make the opener appear on top by clicking on its
chrome;
//this does not happen with IE 6.0 (and maybe older versions as well)

w = window.open("popup.htm", "", "height=200,width=200");
window.onactivate =
window.onfocus =
window.document.onfocus =
window.document.onactive =
window.document.onclick =
window.document.onmousedown =
window.document.body.onclick =
window.document.body.onmousedown =
window.document.body.onresizestart =
window.document.body.onbeforeactivate =
window.document.body.onfocusin =
window.document.body.onactivate =
window.document.body.onbeforeeditfocus =
window.document.body.ondrag =
window.document.body.ondragstart =
window.document.body.onscroll =
window.document.body.onfocus =
window.document.body.onclick =
window.document.body.oncontextmenu =
window.document.body.ondblclick =
window.document.body.onselectstart =
//add or remove events as needed

w.onblur =

function(e){

if (!w.closed){

//cross browser event killing
if (e && e.cancelable){
e.preventDefault();
e.stopPropagation();
}
else if (event){
event.returnValue = false;
event.cancelBubble = true;
}

w.focus();
}
}
</script>
* You can use this other method that may however have adverse effects on
popups that contain elements that receive focus. This method is also fairly
CPU hungry. Additionally it will not prevent sneaky access to the opener
window/document elements (although with some effort, sneaky access may be
possible with the previous method as well). It may also have obtrusive
effects to working with other windows. However, its big plus is that it will
keep the popup on top no matter what (more appropriate if you are building
an underground site with lotsa unsolicited popups).

<script>

w = open("popup.htm", "", "height=200,width=200");

setInterval("if (!w.closed) w.focus();", 100);

</script>

Overall I recommend solution number two. There are cases where such
solutions will cause annoying side-effects but in my experience there are
usually workarounds. Also note that the first script can probably be
appropriately tweaked if you wish to use it with older browsers (like
Netscape 4) as well.

Best regards to the American military!

Fotios
Jul 20 '05 #3

w.onblur =


This line should have been omitted. Just comment it out.

Cheers,
Fotios
Jul 20 '05 #4

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

Similar topics

2
by: WebRod | last post by:
Bonjour, comment savoir en moins de 5 secondes (enfin rapidement quoi) combien de nouveaux messages non récupérés se trouvent dans une BAL sur une serveur POP3 (pas d'imap donc)???? (en sachant...
2
by: grigoo | last post by:
bonjour a tous je me presente a vous::: greg dit le grigoo sur le web ,,etudiant en bioinformatique a montreal et jusqu au cou dans notre language prefere....java. et biojava.. et je suis en un...
0
by: Michael Dyson | last post by:
M. Michael DYSON DIRECTEUR-ADJOINT SOCIÉTÉ DE SÉCURITÉ SARL. TEL.00229 20 21 80 Cotonou République du Bénin Email:michaeldyson2005@latinmail.com Bonjour . Je sais que mon message sera d’une...
0
by: Alejandro Scomparin | last post by:
FORMULACION, PREPARACION Y EVALUACION ECONOMICA Y FINANCIERA DE PROYECTOS DE TECNOLOGIA INFORMATICA (IT) en la UTN Inicia: 17 de Mayo. 19 hs Dirigido a Esta preparado para gerentes, jefes,...
0
by: Alejandro Scomparin | last post by:
FORMULACION, PREPARACION Y EVALUACION ECONOMICA Y FINANCIERA DE PROYECTOS DE TECNOLOGIA INFORMATICA (IT) en la UTN Inicia: 17 de Mayo. 19 hs Dirigido a Esta preparado para gerentes, jefes,...
0
by: gandalf | last post by:
Con motivo del enorme esfuerzo realizado para visitar la ciudad argentina de Córdoba, participar en la Reunión del MERCOSUR, en la clausura de la Cumbre de los Pueblos en la histórica Universidad...
1
by: crow | last post by:
http://www.pagina12.com.ar/diario/elpais/1-72984-2006-09-14.html Por Miguel Bonasso Desde La Habana Me había preparado para verlo, pero la realidad fue mucho más fuerte. Incluso le llevaba de...
1
by: gandalf | last post by:
CON LA PASION DE SIEMPRE HABLO DE CHAVEZ, DE LA MEDICINA CUBANA... Y DE SU PROPIA MUERTE Relato de la nueva gran batalla de Fidel El líder cubano mostró cómo evoluciona su recuperación en el...
1
by: Sebastien | last post by:
Bonjour, Je tient d'abort a m'excuser de poster cette demande ici, mais je ne vois pas tres bien ou fair cette demande, Je développe un logiciel de génération de code (Génération de Code VB et...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.