Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I've making a widget and I need to redirect a parent window to certain url, after specific event in popup, whitch base on another domain. How a can do this.

window.opener.location.replace(url);
                That sounds like cross-domain scripting which is going to be prevented by security limitations; or am I reading the question incorrectly?
– COBOLdinosaur
                Nov 15, 2011 at 18:51

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-US/docs/Web/API/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(...);
                My opener should be on different domain www.mydomain.com . I want to send him some sensitive data. How can I check, if my opener is really www.mydomain.com?
– Ivan Kuckir
                Oct 7, 2015 at 23:31

In certain situations it's possible to do that, but only with different subdomains, not completely different domains. See Cross site scripting on the same domain, different sub domains.

But since postMessage() is widely available in current browsers, you should always prefer postMessage(), as @ian-kuca suggests.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.