Tips on resolving the error message 'Cannot access the property 'document' of null' that occurs when attempting to access window.opener.document

My challenge lies in accessing elements in the parent window from a popup, as I keep encountering an error message that reads 'Cannot read property 'document' of null' whenever I attempt to do so.

Despite reading several posts on this issue, none of the solutions provided have worked for me so far.

I've experimented with different approaches:

openerWindow = window.opener.document;
       selectedTableRow = openerWindow.querySelectorAll(".highlighted-rows");

And also tried:

selectedTableRow = window.parent.document.querySelectorAll(".highlighted-rows");

Although the code above executes without errors, it returns an empty array even when I know there are table rows with the class .highlighted-rows.

Additionally, I attempted:

selectedTableRow = window.opener.document.querySelectorAll(".highlighted-rows");

An intriguing observation is that when I run

selectedTableRow = window.opener.document.querySelectorAll(".highlighted-rows");
directly in the Chrome console, it successfully retrieves the desired row. It's only when integrated into the code that it fails to work.

Answer №1

If a window has been set as an opener, then only it will be able to access it. Check out this documentation for more insights on this topic. Here is the key point:

When a window is opened from another window (either by using Window.open or a targeted link), it keeps a reference to the original window as window.opener. If the current window does not have an opener, this method will return null.

If you are certain that the window you are attempting to reach should have an opener, could you please share the code that created it?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tool for tracking response time on basic Ajax-requested webpage

Looking for an easy way to use ajax to load content onto a page. I want the loaded content to wait before appearing on the page, but using jQuery's .delay() function didn't work as expected. Any suggestions on how to achieve this? Appreciate any ...

The pre-loader is hidden behind the block content and navigation bar

I've encountered an issue with my preloader where it's loading in front of the <body> element but not in front of the site's <navbar> or the {% block content %}. The CSS snippet to increase the z-index of the preloader is as foll ...

JavaScript library error: "Uncaught ReferenceError: numjs is undefined"

Hi there! I've recently started learning JavaScript and am currently exploring the functionalities of NumJS. However, I've encountered an error that's got me stumped. Even though the file "numjs.js" is included locally within the HTML, I kee ...

What is the formula for determining the size of an image using JavaScript, jQuery, or Java?

I'm looking to determine the dimensions of an image. I have both the image src and base64 data available. My goal is to display the current size of the image. I am working with Java and JavaScript. Is there a way for me to calculate the image size usi ...

Updating the filter predicate of the MatTableDataSource should allow for refreshing the table content without needing to modify the filter

Currently, I am working on dynamically altering the filterPredicate within MatTableDataSource to enhance basic filtering functionalities. I want to include a fixed condition for text filtering (based on user input in a search field) for two string columns ...

Determining the location of elements in Three.js: A step-by-step guide

As a newcomer to the world of 3D Graphics programming, I have started using Three.js to develop a software application that involves 3D bin packaging visualization. Currently, my code is focused on creating and positioning two elements. var camera, scene, ...

How to extract the last five words from a .txt file in PHP by utilizing the file_get_contents

Is there a way to efficiently read the last 5 words from a .txt file using file_get_contents during long-polling? I attempted to implement a solution using the code below, but it interferes with the long-polling process – which functions properly when di ...

Issues with CSS properties not functioning correctly within the class.col function

When attempting to apply specific CSS properties to a particular area (e.g., "Dashboard") by assigning the class name "main" to the div.col function in the HTML, I encountered an issue where the CSS property applied affected the entire page. The following ...

Tips on how to choose all elements that do not include a specific value or group of values in cypress

Here's my situation: selector: ".list > div" const velue = [6, 9, 21] Each div contains a different value. I want to remove elements that contain a specific value, then select the first remaining element and click on it. It should look ...

Best method for transferring dynamic data from PHP to JavaScript in Moodle

I have a modal popup within my Moodle filter that requires certain variables to be defined in my PHP script, which I am struggling to set correctly in JS. For example, "MyVariable": define(['jquery', 'core/modal_factory'], function($, ...

Ways to retrieve interface definition using a variable

I have an interface that organizes various states together export interface ScanFiltersStatePage1 { keywords: SensitiveInfoFileKeywordFilter categories: string[] classifications: string[] fileTypes: string[] infotypes: string[] regulations: str ...

Having difficulty extracting image and product names from Amazon or Flipkart pages using Jsoup

I'm having trouble retrieving the main image and product name from Amazon or Flipkart using Jsoup. This is my Java/Jsoup code: // For amazon Connection connection = Jsoup.connect(url).timeout(5000).maxBodySize(1024*1024*10); Document doc = connectio ...

Tips for Maintaining Toastr Notifications on ASP MVC Even After Redirecting to Another Page

I am currently working on an ASP MVC 5 application and encountering an issue with displaying a Toast notification. The toast notification is supposed to appear after updating a user's information to confirm the success of the operation. However, it ...

Is it possible to connect to a Node server from outside the network if the application is only listening on 'localhost'?

When utilizing the Express framework and we implement app.listen(port), the app will be located at localhost:port/ On a local machine, it is clear how to access this address using a local browser running on the same machine. Even clients within the same n ...

Experiencing an issue in Test Cafe when attempting to click on an invisible link using the Client Function

I need to find a way to click on an invisible button in HTML. I attempted to use ClientFunction, however I encountered an error related to the element. import { Selector,ClientFunction } from 'testcafe'; fixture('Clicking Invisible link&apo ...

Performing an AngularJS $http POST request with a combination of JSON parameter and query string

I'm currently trying to write an AJAX call using Angular's $http object in order to send a post request with JSON in the body and a query string appended to the URL. Despite going through the documentation for $http, looking for solutions on SO, ...

Struggling to generate a fresh invoice in my project using React.js

I am fairly new to working with React and could really benefit from some assistance in understanding how to implement a new invoice feature within my current project. The Challenge: At present, I can easily create a new invoice as showcased in the images ...

Using Jquery ajax, I am interested in storing a single value into a variable for future use in JavaScript

I'm finally able to retrieve a JSON Get request, but I'm struggling with utilizing the information effectively. The array contains 9 items, but I only need one specific value - the id. I want to extract this id and save it in a variable for futur ...

Error: The getter callback for the component `RNCSafeAreaProvider` must be a function, but it is currently undefined

After attempting to update my React Native app's dependencies using npm update, chaos ensued. To rectify the situation, I reverted back to the previous package-lock.json, deleted the node_modules folder, and re-ran npm i. Surprisingly, instead of res ...

express.js creating dynamic URLs causing confusion

router.get('/:username', function(req, res, next) { res.render('dashboard'); }); router.get('/', function(req, res, next) { if(req.user) // this has value res.redirect('/'+req.user); }); I'm experi ...