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 7706755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:11:35+00:00 2026-06-01T00:11:35+00:00

How can I check if I have access to window.opener? I’m getting an error

  • 0

How can I check if I have access to window.opener?

I’m getting an error if I open my page in a new window from a file that is not connected with my page (access denied).

Code:

if (window.opener) {
        if (window.opener.document.getElementById('myHidden') !== "undefined") {
            if (window.opener.document.getElementById('myHidden').value == "1" && $("#inputXYZ").val() != "1") {

In line 2 the error occurs. But only if I open the page from a random page (that of course does not have an input field called “myHidden”).
If I open the page from a “valid” page that has such an element, it is working.

  • 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-01T00:11:36+00:00Added an answer on June 1, 2026 at 12:11 am

    You’re comparing an element instance with the string "undefined", and you’re not checking whether window.opener.document is present (I don’t know whether you have to or not, but it’s easy to add). You probably meant:

    // Note: Still not right, see below
    if (typeof window.opener.document.getElementById('myHidden') !== "undefined")
    

    …except that that’s still not correct, because getElementById returns null (not undefined) when there’s no matching element.

    Here’s how I’d do it:

    var input = window.opener &&
                window.opener.document &&
                window.opener.document.getElementById('myHidden');
    var value = input && input.value;
    if (value != "1") {
        // Do something
    }
    

    That uses the curiously powerful && operator (close cousin to the curiously-powerful || operator). The first assignment will short-circuit if window.opener or window.opener.document is “falsey” (null or undefined or 0 or "" or NaN or, of course, false — and those last four don’t apply), resulting in input being undefined. The second assignment will short-circuit if input is falsey, resulting in value being undefined. undefined != "1", so…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I check that I have an open network connection and can contact
How can I check whether all JavaScript functions have loaded properly on a page?
I have a text file. How can I check whether it's empty or not?
How can I check if I have any uncommitted changes in my git repository:
Suppose I have a filehandle $fh . I can check its existence with -e
i have this code in c# doc.SelectSingleNode(WhoisRecord/registrant/email).InnerText how can i check whether it is
If I have... class Bunny < ActiveRecord::Base has_many :carrots end ...how can I check
I have a site where users can log in and check on outstanding support
I want to check if string doesn't have more than 5 numbers. I can
I have 2 forms in my Django view. How can I do a check

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.