Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I have a code that opens a dialogbox to browse for folder path using javascript window.open. This code is called from a Master content page ASP.Net. The problem is from the child node I used window.opener to return the value to a text box in the parent page..but it does not return the value and it does not close the pop-up..here is my code
JavaScript
function SelectAndClose() {
    txtValue = document.getElementById('<%= _browseTextBox%>').value;
    window.opener.document.BodyContent.getElementById('txtRawAnl').innerText = txtValue;
    alert("hello");
    window.close();
}

I am calling this from a JS file and I referenced the JS file on the head tag of the child page.

Thanks!
Posted
Updated 9-Oct-12 10:47am
v2
Comments
Zoltán Zörgő 9-Oct-12 16:43pm    
The child window url is from the same domain? How exactly is the child window opened? The alert you added is showing?
Franco Cipriano 10-Oct-12 9:43am    
How do I know if the URL is from the same domain? the child window is opened by calling window.open from the parent page..and the alert does not show up
Zoltán Zörgő 10-Oct-12 12:37pm    
Well, they are on the same domain if the fqdn part of their url is the same, the rest does not matter. Ex: http://www.a.com/b/c and http://www.a.com/d/e are in the same domain.
Try to put only an alert(window.opener); in the function - it should show an alert regardless of it can or can not access the opener window content itself. And make sure, that there is no Javascript syntactic error on the page.
Franco Cipriano 10-Oct-12 13:05pm    
i got another example from this link http://sorin.serbans.net/blog/index.php/2008/03/19/windowopen-and-passing-values-between-browser-windows/

I revised it and this is how it looked like on my code:

Parent:

function openChildWindow(tagetControlId) {

var s = "BrowseDirectory.aspx?id=" +tagetControlId;
window.open(s,'', 'width=400,height=600,status=no,toolbar=yes,menubar=no,location=no');

return false;
}

Child:

function Done() {
p = window.opener.document; //parent window
alert(window.opener);
target = p.getElementById(GetElementFromQuery(location.search.substring(1), 'id'));
alert('1 ' + target);
target.value = document.getElementById('browseTextBox').value;
alert('2 ' + target.value);
window.close();
}
function GetElementFromQuery(url, name) {
x = url.split("&"); for (i = 0; i < x.length; i++) {
if (x[i].split("=")[0] == name) {
return x[i].split("=")[1];
}
}
return "";
}

I am getting a null on target..but on the example it shows an object..

I tried the example and it worked..but it did not work on my web app..I am calling the child page from a master content page..the examples are 2 not master content pages..does it matter?

Thanks,
Franco Cipriano 11-Oct-12 10:17am    
Just an update on my problem..i tried to replicate this on an ordinary web form and not a master content page and the javascript works..im not sure why it does not work with master content pages

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900