Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How Do I check if document is open?

Posted on 2004-09-15
7
169 Views
Last Modified: 2010-04-06
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
Comment
Question by:stevencopley
7 Comments
 
LVL 33

Expert Comment

by:sajuks
ID: 12071569
// try this
if ( parent.opener)
{
    parent.opener.document.forms[0].submit();
}
0
 

Author Comment

by:stevencopley
ID: 12071590
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
 
LVL 33

Expert Comment

by:sajuks
ID: 12071615
Can you post what you are trying to do . The parent and child code pages
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 33

Expert Comment

by:sajuks
ID: 12071662
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 12074427
Try:

if (parent.opener && !parent.opener.closed)
0
 
LVL 3

Expert Comment

by:xakem
ID: 12078447
if (window.opener)
{
     //your code
     window.opener.document.forms[0].submit();
     //your code
}
0
 
LVL 3

Accepted Solution

by:
xakem earned 500 total points
ID: 12078512
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is the normal amount of queries 5 80
WCAG (Web Content Accessibility Guidelines) levels 3 100
Questions about this React unit test 4 66
.php tree directory? 5 83
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

809 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