Where did you install Firefox from? Help Mozilla uncover 3rd party websites that offer problematic Firefox installation by taking part in our campaign. There will be swag, and you'll be featured in our blog if you manage to report at least 10 valid reports!

Przeszukaj pomoc

Unikaj oszustw związanych z pomocą.Nigdy nie będziemy prosić Cię o dzwonienie na numer telefonu, wysyłanie SMS-ów ani o udostępnianie danych osobowych. Zgłoś podejrzaną aktywność, korzystając z opcji „Zgłoś nadużycie”.

Learn More

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

  • 1 odpowiedź
  • 8 osób ma ten problem
  • 1 wyświetlenie
  • Ostatnia odpowiedź od 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

Wybrane rozwiązanie

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(...);
 }

};

Przeczytaj tę odpowiedź w całym kontekście 👍 1

Wszystkie odpowiedzi (1)

more options

Wybrane rozwiązanie

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(...);
 }

};