Child.onload does not work in IE8 but works in other browsers

Discussion in 'JavaScript' started by rag_gupta, Dec 15, 2010.

  1. #1
    I want set a field of child window. But since the function attached to child.onload does not get called in IE8 how to set the child window form field for IE8 then?

    Currently I'm using a crude way of setInterval 5 seconds so that that field will be set non-stop every 5 seconds since I don't know without onload when the child window has finished loading.
    Here alert("In onload"); will not be called in IE8 but gets called in other browsers.

    Here is the snippet from the html file:
    
    
    <script type="text/javascript">
    	
    	function openWindow(){
    	
    	var child=window.open("index.php?option=com_aicontactsafe&pf=4&tmpl=component",'win2','width=400,height=350,menubar=yes,resizable=yes');
    	
    	if(child!==null)
    	{
    	
    	setInterval(function() {
    	
    			child.document.getElementById("aics_ForDocument_Title").value=window.document.getElementById("documentname").innerHTML; 
    			child.document.getElementById("aics_FormURL").value="$referer"; 
    			child.document.getElementById("aics_FormURL").readOnly=true;
    			child.document.getElementById("aics_FormURL").disabled=true;
    	}, 5000);
    	
    	
    	child.onload=function()
    		{ 
    		alert("In onload");
    			child.document.getElementById("aics_ForDocument_Title").value=window.document.getElementById("documentname").innerHTML; 
    			child.document.getElementById("aics_FormURL").value="$referer"; 
    			child.document.getElementById("aics_FormURL").readOnly=true;
    			
    		};
    	
    	}
    	return false;
    	}
    	</script>
    	<div id="reportthis"><a href="#"  onclick=" openWindow();"><img src="images/instruments/reportthis.jpg" width="110" height="31" alt="Report This" title="Report this document for any issues" /></a></div>
    Code (markup):

     
    rag_gupta, Dec 15, 2010 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    540
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    Hi rag_gupta,
    I haven't look at your actual needs yet,
    but a glimpse at your code prompt me to declare the child var global,
    i.e.

    ...<script type="text/javascript">
    
        [COLOR="seagreen"]var child=null;[/COLOR]
        
        function openWindow(){
        
        [COLOR=red]/*var*/[/COLOR] child=window.open("index.php?option=com_aicontactsafe&pf=4&tmpl=component",'win2','width=400,height=350,menubar=yes,resizable=yes');
        
        if(child!==null){...
    Code (markup):
    This is because you are using 2 (what do we call these, unnamed?) functions.

    Hendra
     
    hdewantara, Dec 16, 2010 IP
  3. rag_gupta

    rag_gupta Member

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Thanks for you reply, but still this does not work in IE8
     
    rag_gupta, Dec 16, 2010 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    Have a function in your child window that passes back the values.
     
    ThePHPMaster, Dec 18, 2010 IP
  5. rag_gupta

    rag_gupta Member

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #5
    Oh child is in a second party library which I can't modify.
     
    rag_gupta, Dec 18, 2010 IP