window.postMessage - difficulties to make it work

纵然是瞬间 提交于 2019-12-08 12:18:56

问题


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.

来源:https://stackoverflow.com/questions/23636016/window-postmessage-difficulties-to-make-it-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!