|
I'm writing a wepabb and I need to use popup windows, which I find problematic sometimes. So I'm writing a script to make them behave, i.e. they will self.close() when out of focus. The problem is that there is a form in the window. Whenever a form item is clicked, the window loses focus and will close unless I devise a system where window closes only if it loses focus while [I]no form object[/I] receives it.
The code below is the HTML page and the associated Javascript. It is a double-conditional test and works fine in Firefox. However, it doesn't work at all in IE: window opens and then closes as soon as any form item is clicked. I need help on this one! Any idea someone? Thanks ;)
[B]page.html :[/B]
[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SWiM Administration - Télécharger un nouveau media</title>
<meta content="SWiM base install" />
<link href="http://exess.dyndns.org/~xspirlet/swim/styles/base/baseadmin.css" rel="stylesheet" type="text/css" />
<link href="http://exess.dyndns.org/~xspirlet/swim/styles/base/base.css" rel="stylesheet" type="text/css" />
<script type="text/javascript"><!--
mmflag = 0;
--></script>
<script type="text/javascript" src="/forum/etc/control1.js"></script>
</head>
<body>
<div class="formi">
<h1>Télécharger un nouveau media</h1>
<p>Types de fichiers autorisés : gif jpeg jpg png <br />
Taille maximale autorisée : 20000 octets</p>
<form action="/forum/upload.html" enctype="multipart/form-data" name="s" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="20000" />
<p><input type="file" name="userfile" /></p>
<p>Télécharger dans le dossier : <br />
<select name="updir">
<option value="">media</option>
<option value="/test2doss">/media/test2doss</option>
<option value="/test2doss/s1-1">/media/test2doss/s1-1</option>
<option value="/test2doss/s1-2-avec">/media/test2doss/s1-2-avec</option>
<option value="/test2doss/s1-2-avec/s1">/media/test2doss/s1-2-avec/s1</option>
<option value="/test2doss/s1-2-avec/s2">/media/test2doss/s1-2-avec/s2</option>
<option value="/test2doss/s1-3">/media/test2doss/s1-3</option>
<option value="/testDoss">/media/testDoss</option>
</select></p>
<p>Insérer comme :<br />
<input type="radio" name="t" value="n" checked="checked" />Non flottant<br />
<input type="radio" name="t" value="l" />Flottant, à gauche<br />
<input type="radio" name="t" value="r" />Flottant, à droite</p>
<p><input class="bright" type="button" name="butcancel" value="Annuler" /> <input class="b" type="button" name="Submit" value="Télécharger" /></p>
<input type="hidden" name="mmflag" id="mmflag" value="0" />
</form>
</div>
</body>
</html>[/CODE]
[B]control1.js :[/B]
[CODE]var closeCondition, closeCondition2;
window.onblur = function() {
if (closeCondition == 1 && closeCondition2 == 0) window.close();
};
window.onfocus = function () {
closeCondition = 1;
};
window.onload = function () {
// The principle is that when a form object receives focus, one of the
// conditions is "closed" (the one that re-engages when window gets back
// the focus) and we activate the second condition, which is done only here
// This script is flawed in that if the focus is passed between form objects
// for a sufficient number of times, the window will close unexpectedly...
document.forms[0].userfile.onfocus = function() { closeCondition = 0; closeCondition2 = 0; };
document.forms[0].userfile.onblur = function() { closeCondition = 0; closeCondition2 = 0; };
document.forms[0].userfile.onclick = function() { closeCondition = 0; closeCondition2 = 0; };
document.forms[0].updir.onfocus = function() { closeCondition = 0; closeCondition2 = 0; };
document.forms[0].updir.onchange = function() { closeCondition = 0; closeCondition2 = 0; window.focus(); };
document.forms[0].updir.onblur = function() { window.focus() };
if(mmflag==1) {
document.forms[0].elements[3].onclick = function() { closeCondition = 0; closeCondition2 = 0; };
document.forms[0].elements[3].onblur = function() { window.focus() };
document.forms[0].elements[4].onclick = function() { closeCondition = 0; closeCondition2 = 0; };
document.forms[0].elements[4].onblur = function() { window.focus() };
document.forms[0].elements[5].onclick = function() { closeCondition = 0; closeCondition2 = 0; };
document.forms[0].elements[5].onblur = function() { window.focus() };
}
document.forms[0].Submit.onclick = function() {
closeCondition = 0;
closeCondition2 = 0;
if(document.forms[0].userfile.value!="") document.forms[0].submit();
else window.focus();
}
document.forms[0].butcancel.onclick = function() {
window.close();
}
document.forms[0].userfile.focus();
window.focus();
};
[/CODE]
<Added>
Sorry for the bbcode not being parsed... It was cut-and-paste and I thought I could edit it later, which I can't :o/ Sorry !
|
|
|
|
|
|
|
|