Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Iexplore - "behave" script doesn't work... help!

    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 no form object 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

    page.html :
    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&eacute;l&eacute;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="etc/control1.js"></script>
    </head>
    <body>
    	<div class="formi">
    	<h1>T&eacute;l&eacute;charger un nouveau media</h1>
    	<p>Types de fichiers autoris&eacute;s : gif jpeg jpg png <br />
    	Taille maximale autoris&eacute;e : 20000 octets</p>
    	
    	<form action="upload.php" 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&eacute;l&eacute;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&eacute;rer comme :<br />
    		<input type="radio" name="t" value="n" checked="checked" />Non flottant<br />
    		<input type="radio" name="t" value="l" />Flottant, &agrave; gauche<br />
    		<input type="radio" name="t" value="r" />Flottant, &agrave; droite</p>
    		<p><input class="bright" type="button" name="butcancel" value="Annuler" /> <input class="b" type="button" name="Submit" value="T&eacute;l&eacute;charger" /></p>
    		<input type="hidden" name="mmflag" id="mmflag" value="0" />
    	</form>
    	</div>
    </body>
    </html>
    control1.js :
    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(); 
    };

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Untested but try this

    PHP Code:
    <script type="text/javascript">
    var 
    closeCondition,closeCondition2;
    var 
    TO;

    window.onblur = function() {
     
    TO=setTimeout('window.close();',500);
    }


    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...
            
    ips=document.getElementsByTagName('INPUT');
            for (
    i=0;i<ips.length;i++){
             if (
    document.all){
              
    ips[i].onfocus=function(){ clearTimeout(TO); }
             }
             else {
              
    ips[i].createAttribute('onfocus','javascript:clearTimeout(TO);');
             }
            }

        
    document.forms[0].updir.onblur = function() { window.focus() };

        if(
    mmflag==1) {
            
    document.forms[0].elements[3].onblur = function() { window.focus() };
            
    document.forms[0].elements[4].onblur = function() { window.focus() };
            
    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();
    };
            
    </script> 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •