How Do I check if document is open?

I want to run the following code but only if the document has not been closed.

parent.opener.document.forms[0].submit();

(if its not open the code crashes)


thanks

Steven Copley
stevencopleyAsked:
Who is Participating?
 
xakemConnect With a Mentor Software Application DeveloperCommented:
sorry the right and the smallest one :) :
if (opener && !opener.closed)
{
     //your code
     opener.document.forms[0].submit();
     //your code
}
0
 
sajuksCommented:
// try this
if ( parent.opener)
{
    parent.opener.document.forms[0].submit();
}
0
 
stevencopleyAuthor Commented:
sorry but it didn't work..

      if(parent.opener){
            alert(1234);
            parent.opener.document.forms[0].submit();
      }


I get the alert come up although the opener is not there any more.

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
sajuksCommented:
Can you post what you are trying to do . The parent and child code pages
0
 
sajuksCommented:
in your parent window declare a variable like this :
var myvar = true

in your popup window
<html>
<head>
<script language="javascript">
<!--
function checkparent() {
    if (opener.myvar) alert("yes")
    else alert("no")
}
//-->
</script>
</head>
<body>
<form>
 <input type="button" value="Valid" onclick="checkparent">
</form>
</body>
</html>
0
 
COBOLdinosaurCommented:
Try:

if (parent.opener && !parent.opener.closed)
0
 
xakemSoftware Application DeveloperCommented:
if (window.opener)
{
     //your code
     window.opener.document.forms[0].submit();
     //your code
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.