Sending a message to the parent window of the browser through a callback function in Internet Explorer version 11.0.x

Currently, I am working on developing a callback in my application that is responsible for opening a popup, executing some tasks, and then responding to the popup's opener window to indicate that the action has been completed.

In order to communicate with the opener window, the popup utilizes the window.opener.postmessage() method within the browser.

While this functionality is functioning properly in most browsers, there seems to be an issue with Internet Explorer 11.0.x as it is unable to successfully post the message. Surprisingly, version 11.192.x is able to communicate effectively. I have not yet tested this with IE 9/10.

The specific error encountered is a Permission Denied message, and the window.opener property is returning as undefined. I am looking for a solution to address this challenge and enable my popup to send messages to the opener window in Internet Explorer 11.0.x.

Any assistance would be greatly appreciated. Thank you!

Answer №1

I have not yet experimented with this method on Internet Explorer, but I would appreciate it if you could provide feedback on whether it works for you or not.

To begin, create an empty object within the window object to store your data.

For example:

window._myData = {};

Next, define a function on the window object that will execute the desired actions, set the data, and be called when the new window is closed.

For instance:


window._popupClosing = function(data){ 
    this._myData = data;
    console.log('Done....', this._myData); 
};

Open the popup window.

For example:

var w = window.open('https://google.com','_blank');

Set a timer to monitor whether the window has been closed. Then, execute your function.

For example:


var timer = setInterval(function(){
    if(w.closed){
        clearInterval(timer);
        window.parent._popupClosing(window.location.href);
    }
}, 1000);

Do not forget to close the new popup using a script within the popup itself by using

window.close();

Putting it All Together


window._myData = {};
window._popupClosing = function(data){
    this._myData = data;
    console.log('Done....', this._myData);
};
var w = window.open('https://google.com','_blank');
var timer = setInterval(function(){
    if(w.closed){
      clearInterval(timer);
      window.parent._popupClosing(window.location.href);
    }
  }, 1000);

Always remember to close the new popup once you have finished. window.close();

If it is possible to send your data to an endpoint and then retrieve it within your popup close function, that would be a more efficient approach compared to transferring data between windows. Just a thought.

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

PHP is unable to retrieve the formData object sent via ajax

I've been experimenting with sending a formData object to PHP (I'm following a tutorial at this link), but I'm encountering some obstacles. Firstly, I create the formData object and fill it with: var formdata = new FormData(); formdata.appe ...

What is the best way to showcase the contents of an array of objects from JavaScript on an HTML page in a dynamic

Looking for guidance in Javascript as a beginner. For an assignment, I need to create two separate JS files and use them to display data dynamically on an HTML page. One JS file, named data.js, contains an array of objects representing a product catalog. T ...

Problems with Vuex getter reactivity when used in conjunction with Vue router

I've encountered an issue with my Vuex getter that fetches data for the current route and displays it in a Vuetify v-data-table. Everything works perfectly fine when the component is initially created. However, when I add a new entry to the data array ...

Setting up D3 on a Meteor Angular2 project

Currently, I am attempting to combine D3 and topojson within the context of Meteor + Angular2. import { Component } from '@angular/core'; import template from './d3map.component.html'; * import 'd3' @Component({ selector: ...

Creating a Timeless Banner with the Magic of `background:url()`

I have a banner placed within a div tag that displays my banner image. I am trying to create a fading effect when transitioning to the next image, but I am struggling to achieve this. I attempted to use jQuery fadeIn(), however, it did not work as expected ...

Obtain JSON data from an API and display it in a table using axios and Vue.js

I am working with a datatable and trying to populate it with data fetched from an API that returns JSON using the findAll() method from Sequelize. However, when I call the getUser method in console.log, it shows that the data is being retrieved. But when ...

JavaScript sorted arrays are an efficient way to keep data

In my dataset, I have an array of objects representing various products. Each product object includes a field called ratingReviews and another field called price, which can either be a string or an object. If the price is represented as an object, it conta ...

The datepicker is refusing to update the date format

I've been attempting to adjust the date format for my datepicker, but it refuses to change. Below is the code I'm using: $(document).ready(function() { $('#dateselect').datepicker({ format: 'dd/mm/yyyy', o ...

Switch between light and dark modes with the MUI theme toggle in the header (AppBar)

I'm currently working on implementing a feature that allows users to switch between dark and light themes in my web app. The challenge I am facing is how to ensure that this theme change functionality is available throughout the entire app, not just i ...

Asynchronous requests in Node.js within an Array.forEach loop not finishing execution prior to writing a JSON file

I have developed a web scraping Node.js application that extracts job description text from multiple URLs. Currently, I am working with an array of job objects called jobObj. The code iterates through each URL, sends a request for HTML content, uses the Ch ...

Track and monitor data modifications in Vue.js

I recently incorporated a Bootstrap Vue Table into my application and wanted to monitor user activity as they navigate through the pages using the pagination feature. Here is where you can find more information on the Bootstrap Vue Table To achieve this, ...

"Enhance the visualization of your data with Apexcharts by accurately coloring the columns

When attempting to color the graphic using an array, only one color is applied to all three columns, despite declaring a different color for each column. options: { chart: { type: 'bar', id: 'chart', }, colors: ['#3 ...

The height of the browser action will not return to its original state

I'm currently working on an extension that provides responses based on user text input. However, I'm running into an issue where the height of the browser action won't reset properly. I've tried various methods to fix this problem, in ...

Creating a basic image carousel with JavaScript, CSS, and HTML

After running the code, I encountered an issue where the first image displays but then after one second, only a white blank screen appears with no further action. It seems like there may be an error in the JavaScript code. Below is the code that was attemp ...

Combining Json, Jquery Autocomplete, and PHP to customize the displayed search options based on multiple items within the Json data

I have a PHP file that returns an array of results, with the 'Name' field being one of them. I want to customize my jQuery autocomplete feature to only search by the 'Name' field and suggest results based on that. However, once a sugges ...

The ng-click event is not triggering the Controller Function as expected

This is the Code for My View <div ng-controller="signupCtrl"> <ul class="list-group" > <li class="list-group-item"> <div class="form-group"> <input type="text" ng-model="signupCtrl.firstName"> ...

Eslint was unexpectedly unable to detect any errors in the .ts files

After creating a SvelteKit project with npm create svelte@latest, I included some .ts files for a particular library. However, when running eslint ., it fails to detect any errors. The default eslint config generated from Svelte is as follows: .eslintrc. ...

KendoGrid encountered a JavaScript runtime error due to an invalid template

Having some trouble navigating the Kendo world and encountering an issue with a grid that is set to a JSON array data source. An error message stating "JavaScript runtime error: Invalid template" is displayed, specifically referencing null values in the d ...

Struggling to understand JSON in joint.js?

I am trying to utilize the joint.js library to render a JSON data as a chart... let paper = new joint.dia.Paper({ el: $('#paper'), width: 600, height: 200, model: graph }); let graph = new joint.dia.Graph; let json = '{"em ...

set ajax url dynamically according to the selected option value

My form features a select box with three distinct choices <select id="tool" name="tool"> <option value="option1">Option1</option> <option value="option2">Option2</option> <option value="option3">Option3</ ...