Click here to Skip to main content
11,411,241 members (63,823 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
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
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 9-Oct-12 11:40am
Edited 9-Oct-12 11:47am
(no name)112.3K
v2
Comments
Zoltán Zörgő at 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 at 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ő at 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 at 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 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 189
1 Maciej Los 108
2 OriginalGriff 88
3 Sascha Lefévre 85
4 BillWoodruff 80
0 Sergey Alexandrovich Kryukov 8,920
1 OriginalGriff 6,918
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100