Uncaught SyntaxError:无法在'Window'上执行'postMessage':在调用'postMessage'时目标源'my_page'无效。 [英] Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin 'my_page' in a call to 'postMessage'

查看:4175
本文介绍了Uncaught SyntaxError:无法在'Window'上执行'postMessage':在调用'postMessage'时目标源'my_page'无效。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本

父页面(pair_pixel_filter.php)

 window.addEventListener("message", function(e) {
            $('#log').append("Received message: " + (e.data));
        }, false);
 $('.photo-upload-btn').click(function(event) {
            event.preventDefault();
            window.open($(this).attr("href"), "popupWindow", "width=600,height=600,scrollbars=yes");
        });

子页

$.ajax({
            type: 'post',
            url: url,
            data: {
                base64data: dataURL
            },
            success: function(data) {
                window.opener.postMessage(data, "pair_pixel_filter.php");
                window.close(); }
        });

基本上打开一个弹出窗口,然后弹出一个ajax,

Basically opening a Popup and then doing some ajax on pop up and returning result to parent. But from Child i am getting this error.


未捕获的语法错误:无法在'Window'上执行'postMessage':目标原点无效pair_pixel_filter在调用'postMessage'中的.php'

Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin 'pair_pixel_filter.php' in a call to 'postMessage'


推荐答案

$ c> postMessage 是目标原点。这是网页所在的,而不是(php)文件的名称。

The 2nd parameter to postMessage is the "target origin". This is the domain where the page is located, not the name of the (php) file.

它需要是这样的: / p>

It needs to be something like:

window.opener.postMessage(data, "http://example.com");

请参阅: https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage

这篇关于Uncaught SyntaxError:无法在'Window'上执行'postMessage':在调用'postMessage'时目标源'my_page'无效。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆