修改父页面的值可以这样:
window.parent.document.getElementById('username').value='redice';
调用父页面的JS函数可以这样:
window.parent.test();
实例代码如下:
/*父页面的test函数*/
function test()
{
alert('父页面的test函数被调用!');
}
上述代码已通过IE,FF,Chrome测试。
注意:在本地直接用IE和FF打开测试正常,但用Chrome直接打开测试无效。网上有人说是Chrome不支持window.parent。后来看到stackoverflow上的一个类似的提问,原来Chrome不允许采用file:协议引用父窗口,放到Web容器中测试就正常了。
原帖如下:
It seems that Chrome browser doesn't permit to reference a parent window accessing pages with thefile:protocol. In fact I tested above code with files on my machine, so with a url likefile:///C:/mytests/mypage.html. If I put that page in a Web Server, it all works as expected.