2014-09-23 27 views
1

我有一个要求,如果我点击一个按钮,将会调用一个函数,其中将会调用 1.打开新选项卡中的给定html链接 2.然后访问新打开的html DOM在新选项卡中打开一个html并访问它的DOM元素

我想这样的事情在我的函数调用:

function GenerateReport() { 
window.open('./qunit/EditOpenSave.html','_blank'); 
//////window.location.href = "./qunit/EditOpenSave.html"; 
document.getElementById("inputTextToSave").value = "Show me !!!"; 
} 

但在这里它成功打开该链接,而不是访问它的DOM。 请帮助..

+2

请尝试搜索:http://stackoverflow.com/questions/1258563/how-can-i-access-the-dom-tree-of-child-window – RichieAHB 2014-09-23 10:45:23

+0

谢谢richieahb! – 2014-09-23 11:17:50

回答

2

我试过这种方式,它的工作!

function GenerateReport() { 
newTab = window.open('./qunit/EditOpenSave.html','_blank'); 
$(newTab.document).ready(function() { 
$(newTab.document).contents().find('#inputTextToSave').html("asdfasdf"); 
}); 
}