Solved

How Do I check if document is open?

Posted on 2004-09-15
7
168 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

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…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 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