how to communicate data between parent and child window from different http domain?

StackOverflow https://stackoverflow.com/questions/20864668

  •  23-09-2022
  •  | 
  •  

Pregunta

I've been working on some sort of 'remote controller' window where the child window loads the selling configuration from the parent and after changing the selling configuration and pressing the 'apply' button, the selling configuration is sent back to the parent window.

After googling, I found out that data exchange between the parent and child is available only if both windows are opened under the same http:// domain.(I believe this is because of the unique SSL that every server has.)

then, here's my question: is there anyway that I can exchange data between parent and child window when two windows have different domain?

more details on the situation that I'm stuck on:

  • I'm trying to make a child window that will allow me to select which metal ores to sell in a petty web game called 'Mr.mine'(mrmine.com)
  • with the chrome javascript console, I've managed to have some control over the game where I can create such loops that will to the selling instead for me
  • Originally, if I were to select which ores were to sold, I would have had to manually change an array called 'sellorder' from the java console. This turned out to be quite confusing and frustrating so I wanted to create a child window where I could configure my selling decisions with a much simpler and easy to understand layout.
  • I succeeded in making such a child window in my github repository and I have confirmed successful data exchange between the parent and child window which are both located in the same github repository.

parent code:

    var sellorder=[....] // has some value..

    // some codes in between...

    function sell(){
    var url="https://rawgithub.com/kwagjj/mrmine-macro/master/initializing/sell_window_ver1.0.html"
    var w=window.open(url,"sell_window","width=300,height=450");
    }

child code:

    var loadarray;
    window.onload=function(){
         loadarray=window.opener.sellorder;}

    // ... after some operations..

    window.opener.sellorder=loadarray;
  • Then I tried to implement this child window popup code into mr.mine.
  • It turned out to be a failure. And I think this is because in this case, the parent and child window doesn't share the same http:// domain.

So this is my situation. If there isn't a direct way of exchanging data between the two windows, I would like to hear any other way to even bypass this problem.

¿Fue útil?

Solución

"with the chrome javascript console" (sic) you can also add some javascript to your page (or use an extension like greasemonkey for custom scripting).

On your game add a script with a setInterval function that will call with your server every x seconds. And get the json encoded data of the configuration

On the other side, when validating your configuration, it will use Ajax to store information on your server (i.e. in a file)

To sum up :

In your parent windows, when you modify your configuration, an Ajax call is made to save the new config json encoded in a file on your server

In your child windows with the console (if no reload) or with a userscript extension (like GreaseMonkey) you add a setInterval javascript to load the array from the file on your server.

PS: This is theorical and not an invitation to cheat on a game you like.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top