將父窗口的javascript函數傳遞給子窗口時出現問題。在Firefox和Chrome中運行良好,但在IE中無法運行(使用IE11測試)。具有諷刺意味的是,即使在IE中打開F12開發工具,它也能工作。這是在同一個域中,所以跨域塊應該不成問題。我曾嘗試:將javascript函數傳遞給用window.open()打開的子窗口
// on the parent
var newWin = window.open('href', 'title', '');
newWin.myFunc = function() { alert('test'); };
// on the child (when calling this I get error: 'myFunc' is undefined)
myFunc();
我知道我可以去周圍其他方式 - 呼籲從孩子父定義的函數:
// on the parent
function myFunc() {
alert('test');
}
// from child
opener.myFunc();
但超出此問題的範圍原因我需要能夠將匿名函數傳遞給它必須能夠執行的子項。
您正在測試的函數調用alert,還是執行其他操作並使用'console.log'? 'console'在IE中不存在,直到控制檯打開,所以'console.log'會拋出一個錯誤並停止其他事情的發生,這取決於你擁有它的位置。 – Ryan 2014-09-05 23:45:30
實際功能不調用alert()和console.log。它做了一些與UI沒有任何關係的數據操作。 – Perry 2014-09-06 00:11:52
在這裏黑暗中拍攝,你試試window.parent.myFunc();然而? – 2014-09-06 00:31:28