Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xmlhttp request to parent page and self close

Status
Not open for further replies.

travisbrown

Technical User
Joined
Dec 31, 2001
Messages
1,016
I'm refreshing an object in a parent window when closing a popup. I thought i could just use self.close(), but it messes stuff up.

FF js console gives me "http is not defined" on this line in the second function: if ( http.readyState == 4 ) {

Refreshes properly when I take self.close out. Any hints?

Code:
<a href="javascript:sndParentReq('call_index.asp?key=<% = LEFT(song_title,1) %>','songlist');self.close();" ><img src="_images/exit.gif" class="savebutton" /></a>

var http = createRequestObject();

function sndReq(page,insert) {
    http.open( 'get', page );
    http.onreadystatechange = function(){
		 if ( http.readyState == 4 ) {
        var response = http.responseText;
        document.getElementById(insert).innerHTML = response;
		}	
	};
    http.send(null);
}

function sndParentReq(page,insert) {
    http.open( 'get', page );
    http.onreadystatechange = function(){
		 if ( http.readyState == 4 ) {
        var response = http.responseText;
        opener.document.getElementById(insert).innerHTML = response;
		}	
	};
    http.send(null);
}
 
Oh, I see. I thought once it was changed, it was changed since I could close the page manually.

Any ideas on a process so I can 1. show the changes in the parent page without doing a complete opener refresh 2. close the popup?

The functions are in an outfile. Can an event trigger a function on the parent page? Sort of wrap the function in another so it is the parent calling the httpxml, not the popup?
 
Yes - you should be able to use a "send" function in the opener instead of the popup with no problem. Use "opener.sndParentReq" instead of "sndParentReq" (assuming you move the functions to the opener, of course).

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hmm... look like there is anything wrong with this? Still can't get it to close the popup. sndReq is firing okay, but window won't close.

Code:
<script type="text/javascript">
opener.sndReq('call_profiles.asp?str=help','autocomplete_lanid');
opener.sndReq('call_profile.asp?lanid=help','profile');
opener.document.getElementById('txt_lanid').value = 'help';
self.close;
</script>
 
~bump~

Maybe I should ask first: is it possible to self.close a window after calling a opener function?
 
I refer only to the script in the first post.

[1] Make out a function foldup() say in the popup page. (I assume http is of scope global.)
[tt]
function foldup() {
if (http && (http.readyState==4)) {
setTimeout("window.close()",100);
} else {
setTimeout("foldup()",100);
}
}
[/tt]
[2] Change the anchor element to calling it.
[tt]
<a href="javascript:sndParentReq('call_index.asp?key=<% = LEFT(song_title,1) %>','songlist');[blue]foldup()[/blue]" ><img src="_images/exit.gif" class="savebutton" /></a>
[/tt]
I assume proper functioning of the rest.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top