2014-09-23 29 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"); 
}); 
}