1
我有一些代码正在调用一个存在于window.external上的函数的html页面中运行。代码工作:通过javascript设置iframe的window.external成员
SomeCode.js(生活在somePage.html):
window.external['someFunction']();
然而,出于测试目的,我需要嵌入在一个单独的测试页的iframe内的HTML页面。测试页代码
TestPage.html:
window.frames[0].external['someFunction'] = function() { console.log('success'!); }; // Doesn't work
window.frames[0].src = "http://somePage.com/somePage.html";
window.frames[0].external['someFunction'] = function() { console.log('success'!); }; // window.external['someFunction'] is still null from the perspective of the code in SomeCode.js. oesn't work
我已经尝试了一些前后都设置SRC后设置功能的方法。奇怪的是,如果我打印window.frames [0] .external到控制台,window.frames [0] .external DOES似乎有'someFunction'设置。它几乎就像window.frames [0] .external是与iframe中javascript内部使用的对象不同的对象。
任何想法将不胜感激。
感谢, 蝉