与此类似的问题很少,但在我的情况下没有一个解决方案有效。我对此很陌生,所以问题也可能是我缺少的基本问题。
在点击的情况下,我试图用点击的对象打开一个新标签,所以现在我只是想在新标签中提醒它。
父窗口代码:
$(document).on("click", ".button", function(){
var toSend = $(this);
var newTab = window.open("test.html", "_blank");
newTab.myData = toSend; // this one was a solution for a similar problem,
// didn't work for me.
});
这是打开的窗口:
$(document).ready(function() {
console.log(window.parent.toSend);
console.log(window.parent.myData);
console.log(myData);
console.log(window.opener.toSend);
});
前 2 个日志返回“未定义”,第三个是抛出 myData 未定义的异常(未捕获的 ReferenceError:myData 未定义)。对于后一个日志,我得到“Uncaught SecurityError: Blocked a frame with origin "null" from access a frame with origin "null"。协议、域和端口必须匹配。”
帮助将不胜感激,谢谢!
编辑:console.log(toSend) 确实记录了正确的对象,并且被定义了。