Solved

Javascript: if child doesn't exist, don't try and close it.

Posted on 2003-11-04
5
593 Views
Last Modified: 2010-05-18
I am new to javascript so I am not sure how to word my code.

I have a perl script which comes back to the same html page more than once, but the child window isn't always open... and the code I have will try and close the window even if it doesn't exist. I need to check to see if the child window exists first.


Current code:

<SCRIPT LANGUAGE="JavaScript">

<!--

function body_OnLoad() {
  document.form_SleepChild.submit();
}

//-->
</SCRIPT>



Desired code:

<SCRIPT LANGUAGE="JavaScript">
<!--

function body_OnLoad()
{
         if(exist.childWindow_name)
         {
         document.form_SleepChild.submit();
         }
}

//-->
</SCRIPT>


Any help would be much appreciated.

Thank you :)
0
Comment
Question by:dr34m3rs
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 125 total points
ID: 9680618
myWin=window.open('','','');

<SCRIPT LANGUAGE="JavaScript">
<!--

function body_OnLoad()
{
         if(myWin && !myWin.closed)
         {
         document.form_SleepChild.submit();
         }
}

//-->
</SCRIPT>

0
 
LVL 1

Author Comment

by:dr34m3rs
ID: 9680784
Ok that worked great Jester_48, so I will accept your answer.

I do get a javascript error icon on the very lower left corner of my IE browser though. Just curious if there is any way to keep this from happening?

Thank you for all your help :)
0
 
LVL 1

Author Comment

by:dr34m3rs
ID: 9680840
The error I get is wildchild undefined...
0
 
LVL 1

Author Comment

by:dr34m3rs
ID: 9680852
nevermind I solved it :)

Thanks.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9680998
thanks for the points
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now