gpt4 book ai didi

javascript - 未捕获的语法错误 : Failed to execute 'postMessage' on 'Window' : Invalid target origin 'my_page' in a call to 'postMessage'

转载 作者:可可西里 更新时间:2023-11-01 01:23:50 25 4
gpt4 key购买 nike

我有以下脚本

父页面(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 并将结果返回给父窗口。但是从 Child 我收到了这个错误。

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

最佳答案

postMessage 的第二个参数是“目标来源”。这是页面所在的,而不是 (php) 文件的名称。

它需要是这样的:

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

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

关于javascript - 未捕获的语法错误 : Failed to execute 'postMessage' on 'Window' : Invalid target origin 'my_page' in a call to 'postMessage' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23373376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com