Join the AMA (Ask Me Anything) with Firefox leadership team to talk about Firefox priorities in 2024. Mark your calendar! Thursday, June 13, 17:00 - 19:00 UTC.

সহায়তা খুঁজুন

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

How to access parent window in javascript when popup is in a different domain

  • 1 উত্তর
  • 8 এই সমস্যাটি আছে
  • 135 দেখুন
  • শেষ জবাব দ্বারা Dyvik Chenna

more options

I have an html page in www.x.com domain that open a popup with window.open containing another page in www.y.com domain and i want these page to comunicate with window.postMessage, how can i access to parent page within the popup ? I tryed window.opener but it is undefined

I have an html page in www.x.com domain that open a popup with window.open containing another page in www.y.com domain and i want these page to comunicate with window.postMessage, how can i access to parent page within the popup ? I tryed window.opener but it is undefined

সমাধান চয়ন করুন

You just cannot do that. Cross-site scripting is not allowed in most browsers.

You can, however, communicate with the other window via cross-document messaging described here: https://developer.mozilla.org/en/DOM/window.postMessage

The most you can to is to send a message from the popup to the opener and listen for such message in the opener. The opener then has to change its location on its own.

// popup: window.opener.postMessage('replace your location', '*');

// opener: window.onmessage = function (e) {

 if (e.data === 'replace your location') {
   window.location.replace(...);
 }

};

প্রেক্ষাপটে এই উত্তরটি পড়ুন। 👍 1

All Replies (1)

more options

চয়ন করা সমাধান

You just cannot do that. Cross-site scripting is not allowed in most browsers.

You can, however, communicate with the other window via cross-document messaging described here: https://developer.mozilla.org/en/DOM/window.postMessage

The most you can to is to send a message from the popup to the opener and listen for such message in the opener. The opener then has to change its location on its own.

// popup: window.opener.postMessage('replace your location', '*');

// opener: window.onmessage = function (e) {

 if (e.data === 'replace your location') {
   window.location.replace(...);
 }

};