How do you access child window data from the parent window?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcelrob5
    New Member
    • Jun 2010
    • 19

    #1

    How do you access child window data from the parent window?

    I have this onclose function for a window that in it it is suppose to grab data from the child window and store it the parent the parent then sends it via ajax to and jsp to store the data in a database. The code is shown below

    Code:
    var auditpop;
    
    	
    
    	function auditPopup(){
    		var map = {"userid" : temp_user};
    		jQuery.ajax({
    			type: "GET",
         		url: '/auditwizard-portlet/checkInProgress.jsp',
         		dataType: "html",
         		data: map,
         		global: true,
         		success: function(responseHTML){
         			var audit_war = "/auditwizard-portlet/view.jsp?userid=<%out.print(users);%>";
    				auditpop = dhtmlmodal.open("auditbox","iframe",audit_war,"Athena Audit Wizard","width=1180px,height=700px,scrolling=1,center=0,top=5px,left=5px");
    				auditpop.onclose =	function(){var audit_data = auditpop.document.getElementById("audit_main_div").innerHTML;
    												var map = {"app" : auditpop.auditedApp
    				  											, "user" : <%out.print(users);%>
    				  											, "time" : auditpop.timestamp
    				  											, "data" : audit_data};
    												var save_url = "/auditwizard-portlet/SaveAuditToDB.jsp?random="+Math.floor(Math.random()*1000);
    												jQuery.ajax({type: "GET",url: save_url,dataType: "html",data: map,global: true,
    													success: function(responseHTML){
    														alert("Save Successful");
    													},
    													error: function(xhr, status, e){
         														if(xhr.status ==500){
         																alert("Please Contact Athena with error description");
         														}else if(xhr.status == 404){
         														}else{
         															alert("Error has occured with "+xhr.status);
         														}
         												}
    												
    												});
    												};				
         		},
         		error: function(xhr, status, e){
         			if(xhr.status ==500){
         				alert("Please Contact Athena with error descript");
         			}else if(xhr.status == 404){
         			}else{
         				alert("Error has occured with "+xhr.status);
         			}
         		}
         	});
    Can anyone tell why this isn't working and/or how to fix it?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    what part exactly isn't working?

    Comment

    • mcelrob5
      New Member
      • Jun 2010
      • 19

      #3
      The section of code in the onclose function where it is trying to gather information from the child window (auditpop). Mainly thr section of below.

      Code:
      {var audit_data = auditpop.document.getElementById("audit_main_div").innerHTML;
                                                      var map = {"app" : auditpop.auditedApp
                                                                    , "user" : <%out.print(users);%>
                                                                    , "time" : auditpop.timestamp
                                                                    , "data" : audit_data};
      I have tried using alert to send back what it is getting and it keeps returning undefined. And before anyone asks (not meaning to be rude with my wording) yes the names of the div and the variables are correct, I have checked multiple times on that.

      Can anyone tell why this isn't working?

      Oh and the code it running in IE8 (if that helps)

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Oh and the code it running in IE8 (if that helps)
        does it work in Firefox or Chrome?

        Comment

        • mcelrob5
          New Member
          • Jun 2010
          • 19

          #5
          I haven't checked because the overall application is only meant to run in IE. I used this site



          and it got to the point i am right now. But still it doesn't seem to work. Could it be that the child window is an iframe or something?

          Also, I have my internet options set to allow almost anything and everything to occur for development purposes.

          Comment

          • mcelrob5
            New Member
            • Jun 2010
            • 19

            #6
            I think I have found the solution. It has to do with the fact that I am using dhtmlmodal window object. I cannot directly reference the window object (auditpop) in the onclose function instead i have to define it in reference to its content so i had to replace the auditpop in the onclose function with this.content. ...

            Thank you for your replies.

            Comment

            Working...