| | |
Parent/Child Windows
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2007
Posts: 13
Reputation:
Solved Threads: 0
I am new to DOM and need a little help. I have opened a named page with window.open. Later when the user clicks on the link from the parent page that was used to open the child window, they are confused because they think the function doesn't work. Of course, the page is already open. All I need is the code to bring the child window back to the front. I assume I will need to use focus() and have tried everything I can think of. Do I need an if statement on the function that opens the child window to determine if the child window is already open and what is the DOM code i.e. window.childWindowName.focus()? Thanks in advance for your help!
Last edited by JC4QLx3; Jul 31st, 2007 at 10:07 am.
When the button is clicked, check to see if the window is already open using the 'window.closed' property which returns a boolean. If the child window is open, just give it the focus using the function 'focus()' and if it isn't then open a new one.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> <head> <script> var wnd = null; function openit() { if(!wnd || wnd.closed) wnd = window.open("http://www.google.com"); else wnd.focus(); } </script> </head> <body> <form> <input type="button" value="Open" onclick="openit();" /> </form> </body> </html>
Last edited by ~s.o.s~; Jul 31st, 2007 at 3:07 pm.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
Join Date: Jul 2007
Posts: 13
Reputation:
Solved Threads: 0
I truly appreciate your help. I modified my script per your sample (I think), but it doesn't work. With what I have here the window doesn't open. Do you or anyone else see the problem?
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<SCRIPT> var name = null; function openWindow(url,name) { if(!name || name.closed) { var windowHeight,windowWidth,windowTop,windowLeft windowHeight = screen.availHeight; windowWidth = screen.availWidth; windowTop = 0; windowLeft = 0; var varStore = ""; varStore = varStore + "width=" + windowWidth; varStore = varStore + ",height=" + windowHeight; varStore = varStore + ",resizable=" + "1"; varStore = varStore + ",scrollbars=" + "0"; varStore = varStore + ",menubar=" + "0"; varStore = varStore + ",toolbar=" + "0"; varStore = varStore + ",directories=" + "0"; varStore = varStore + ",location=" + "0"; varStore = varStore + ",status=" + "1"; varStore = varStore + ",left=" + windowLeft; varStore = varStore + ",top=" + windowTop; varStore = varStore + ",ScreenX=" + windowLeft; varStore = varStore + ",ScreenY=" + windowTop; window.open(url,name,varStore) } else { name.focus(); } } </SCRIPT> <P align="center"><A href="javaScript:openWindow('member_panel.php?page=BO_Home','BO_Home')"><IMG src="http://qlx3.net/images/home.png" alt="Home" width="256" height="217"></A></P>
Last edited by JC4QLx3; Aug 1st, 2007 at 12:09 am.
Your code does not run because you ignore the important aspects of the code posted by me. You have a global variable called 'name' and at the same time have a local variable 'name'. Because of this the local one hides the global one. Change the name of the function variable to something else than 'name'.
The second mistake you make is of not assigning the reference of the newly opened window to the variable 'name'. See my previous example for more info and post your code if it still doesn't work.
The second mistake you make is of not assigning the reference of the newly opened window to the variable 'name'. See my previous example for more info and post your code if it still doesn't work.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
Join Date: Jul 2007
Posts: 13
Reputation:
Solved Threads: 0
I do not see the difference between what you did and what I did. Anyway, would you like to earn money for your advice. We have need for a developer with these skills. Please send your contact info to gojimgo@insightbb.com. If you do that, please send your response with read receipt, so I don't just throw it away.
Do something like this:
Oh and BTW, get into the habit of using lowercase alphabets for tag names as we are now in the XHTML era.
<SCRIPT>
var name = null;
function openWindow(url, named)
{
if(!name || name.closed)
{
var windowHeight,windowWidth,windowTop,windowLeft
windowHeight = screen.availHeight;
windowWidth = screen.availWidth;
windowTop = 0;
windowLeft = 0;
var varStore = "";
varStore = varStore + "width=" + windowWidth;
varStore = varStore + ",height=" + windowHeight;
varStore = varStore + ",resizable=" + "1";
varStore = varStore + ",scrollbars=" + "0";
varStore = varStore + ",menubar=" + "0";
varStore = varStore + ",toolbar=" + "0";
varStore = varStore + ",directories=" + "0";
varStore = varStore + ",location=" + "0";
varStore = varStore + ",status=" + "1";
varStore = varStore + ",left=" + windowLeft;
varStore = varStore + ",top=" + windowTop;
varStore = varStore + ",ScreenX=" + windowLeft;
varStore = varStore + ",ScreenY=" + windowTop;
name = window.open(url,name,varStore)
}
else
{
name.focus();
}
}
</SCRIPT>
<P align="center"><A href="javascript:openWindow('member_panel.php?page=BO_Home','BO_Home')"><IMG src="http://qlx3.net/images/home.png" alt="Home" width="256" height="217"></A></P>Oh and BTW, get into the habit of using lowercase alphabets for tag names as we are now in the XHTML era.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Good point, I missed that one. But considering there are no attributes having the name 'name' in the global namespace (window), there is no harm as such. I for one, don't prefer using such names as my variable names.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
Join Date: Jul 2007
Posts: 13
Reputation:
Solved Threads: 0
Thanks, you are being so helpful! We are very close. The only problem left to resolve is that the user cannot open the 3 different windows at the same time, which we want. The reason is that we need to set name to 'null' for every attempt. The following was my attempt to do that, but it creates an error. Note that I moved the var name = null; to within the function call.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<SCRIPT> function openWindow(url, named) { var name = null; name = named; if(!name || name.closed) { var windowHeight,windowWidth,windowTop,windowLeft windowHeight = screen.availHeight; windowWidth = screen.availWidth; windowTop = 0; windowLeft = 0; var varStore = ""; varStore = varStore + "width=" + windowWidth; varStore = varStore + ",height=" + windowHeight; varStore = varStore + ",resizable=" + "1"; varStore = varStore + ",scrollbars=" + "0"; varStore = varStore + ",menubar=" + "0"; varStore = varStore + ",toolbar=" + "0"; varStore = varStore + ",directories=" + "0"; varStore = varStore + ",location=" + "0"; varStore = varStore + ",status=" + "1"; varStore = varStore + ",left=" + windowLeft; varStore = varStore + ",top=" + windowTop; varStore = varStore + ",ScreenX=" + windowLeft; varStore = varStore + ",ScreenY=" + windowTop; name = window.open(url,name,varStore) } else { name.focus(); } } </SCRIPT>
•
•
Join Date: Jul 2007
Posts: 13
Reputation:
Solved Threads: 0
•
•
•
•
Good point, I missed that one. But considering there are no attributes having the name 'name' in the global namespace (window), there is no harm as such. I for one, don't prefer using such names as my variable names.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<SCRIPT> <!-- // create a custom window function openWindow(url, wnd) { var theName = null; theName = wnd; if(!theName || theName.closed) { var windowHeight,windowWidth,windowTop,windowLeft windowHeight = screen.availHeight; windowWidth = screen.availWidth; windowTop = 0; windowLeft = 0; var varStore = ""; varStore = varStore + "width=" + windowWidth; varStore = varStore + ",height=" + windowHeight; varStore = varStore + ",resizable=" + "1"; varStore = varStore + ",scrollbars=" + "0"; varStore = varStore + ",menubar=" + "0"; varStore = varStore + ",toolbar=" + "0"; varStore = varStore + ",directories=" + "0"; varStore = varStore + ",location=" + "0"; varStore = varStore + ",status=" + "1"; varStore = varStore + ",left=" + windowLeft; varStore = varStore + ",top=" + windowTop; varStore = varStore + ",ScreenX=" + windowLeft; varStore = varStore + ",ScreenY=" + windowTop; theName = window.open(url,theName,varStore) } else { theName.focus(); } } //--> </SCRIPT> <P align="center"><A href="javascript:openWindow('member_panel.php?page=BO_Home','BO_Home')"><IMG src="http://qlx3.net/images/home.png" alt="Home" width="256" height="217"></A></P>
Last edited by JC4QLx3; Aug 2nd, 2007 at 1:13 am.
![]() |
Similar Threads
- Parent/Child Windows References (JavaScript / DHTML / AJAX)
- how can I fix two child windows in a mdi form in vb 4 (Visual Basic 4 / 5 / 6)
- ASP.NET 2.0, Parent/Child Data Control? (ASP.NET)
- Displaying a different bitmap in different child windows? - win32 in C (C)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Javascript Function Link
- Next Thread: loader page
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxexample ajaxjspservlets api blackjack browser bug calendar captchaformproblem checkbox child class close cookies createrange() cursor dependent disablefirebug dom dropdown editor element embed engine events explorer ext file firehose flash form forms game gears google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe image() images internet java javascript javascripthelp2020 jquery jsf jsfile jump libcurl math matrixcaptcha media mp3 mysql object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post progressbar rated regex runtime scroll search security session shopping size software solutions sql star stars stretch synchronous text textarea tweet unicode web webservice window windowsxp wysiwyg xspf \n






