Search code examples
javascriptinputbox

Send data between input boxes in different pages


I would like to make an inputbox which sends the data to another inputbox in a new tab ( and a new page ) with a button or etc. I searched for it a lot ( url data transfer & ... ) but still have no idea . I appreciate any start point or sth. Thanks ! Edit : they are different sites with different domains. Edit 2 : I don't have any accesses to edit the receiver page.


Solution

  • For cross-domain messaging I would suggest utilizing postMessage.

    Browser support is fair enough, and the API is very very easy:

    //create popup window
    var domain = 'http://scriptandstyle.com';
    var myPopup = window.open(domain + '/windowPostMessageListener.html','myWindow');
    
    //periodical message sender
    setInterval(function(){
        var message = 'Hello!  The time is: ' + (new Date().getTime());
        console.log('blog.local:  sending message:  ' + message);
        myPopup.postMessage(message,domain); //send the message and target URI
    },6000);
    
    //listen to holla back
    window.addEventListener('message',function(event) {
        if(event.origin !== 'http://scriptandstyle.com') return;
        console.log('received response:  ',event.data);
    },false);
    

    The above example code was taken from this article by David Walsh.