window.postMessage - difficulties to make it work

784 views Asked by At

I try to establish communication from PayPal Ipn.php script (when "Completed" message is received - that part is tested and works well), and the original page of Form that contains a submit button. The idea is to have the submit button clicked.

The 2 pages are on same domain using the same protocol.

Here is my script on Ipn.php script:

$click = "<script> 
window.postMessage('Completed', 'http://www.example.com');
</script>";
echo $click;
echo "test"; // I receive it.

After further testing the Receive part works, but the send part (above) does not.

Here is my script on original form that contains the Submit button:

 $(window).load(function() {
 window.addEventListener('message', receiver, false);
 function receiver(e){
 if (e.origin == 'http://www.example.com'){
    if (e.data == 'Completed') {
        alert(e.data);
        e.source.postMessage('OK', e.origin);
$("#submit").click();
    } else {
        alert(e.data);
        e.source.postMessage('FAIL', e.origin);
    }
}
}
;})

Results so far: Does not work, the send part does not work (after testing the receiving part).

Thanks in advance for your help.

0

There are 0 answers