Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8292071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:20:39+00:00 2026-06-08T13:20:39+00:00

I have the below script on a page, let’s say child.html. I only want

  • 0

I have the below script on a page, let’s say “child.html”.

I only want the browser to see the function opener.opener = opener; opener.close() if the referring URL is the one listed in the if statement of the script (parent.html), otherwise I don’t want the browser to see it.

The page that this script is on is a child page (a popup) of a parent page. Users (hopefully) will only access the parent page, which will subsequently open this child page and close the parent page at the same time using the opener.opener = opener; opener.close() function.

The function works fine and does what I need it to do (closes the parent after opening the popup). But, if the child page URL is accessed directly (in other words without being directed from the parent page), then obviously there is no parent page to close and I get the script error:

‘opener’ is null or not an object

I understand the error message, hence why I’m trying to hide ‘opener’ if the referring URL IS NOT parent.html so that if someone happens to access the child page directly, opener is hidden and no error message.

What do I need to change in the below script to make this work?

        <script type="text/javascript">
        //<![CDATA[<!--
        if (document.referrer != '../parent.html') {
        opener.opener = opener;
        opener.close();}
        else {}
        //-->
        //]]>
        </script>

Alternatively, I tried writing the following:

        <script type="text/javascript">
        //<![CDATA[<!--
        if (document.referrer = '../parent.html') {
        return false;
        } else {
        opener.opener = opener;
        opener.close();}
        //-->
        //]]>
        </script>

But that returns the script error: ‘return’ statement outside of function.

Thanks very much in advance for any help you can offer!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:20:41+00:00Added an answer on June 8, 2026 at 1:20 pm

    Your first script is correct if you put an ANDcondition with the initialization of opener variable like:

     if (document.referrer !== '../popup.html' && opener) { ... }
    

    For the second one you have to write down a function if you want to use the return statement like:

    <script type="text/javascript">
       //<![CDATA[<!--
       function(){
         function myFunct() {
           if (document.referrer === '../parent.html' || !opener) {
             return false;
           } else {
             opener.opener = opener;
             opener.close();
             return true;
           }
        }
        myFunct();
       }();​
       //-->
       //]]>
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below java script function in which I want to redirect the
I have tested the below script on a demo page which is not using
I have the below line in the unix shell script. I want to exclude
I have a NAnt script like below: <target name=Init unless=${target::has-executed('Init')}> What I want is
I have a bash script as below, and I want it to read two
I have Javascript as below: <script type="text/javascript" language="javascript"> function redirectToPrevious(abcURL) { window.location.replace(abcURL); } function
I only have one function in my scripts page, and it is giving me
I have the following script below where I try to mimic a file upload
I have the script shown below that displays a list of records from a
I have a NAnt script like below: <if test=${a}>${b}> <call target=target/> </if> What I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.