• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

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
0
stevencopley
Asked:
stevencopley
1 Solution
 
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
 
sajuksCommented:
Can you post what you are trying to do . The parent and child code pages
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
xakemCommented:
if (window.opener)
{
     //your code
     window.opener.document.forms[0].submit();
     //your code
}
0
 
xakemCommented:
sorry the right and the smallest one :) :
if (opener && !opener.closed)
{
     //your code
     opener.document.forms[0].submit();
     //your code
}
0

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now