2012-08-10 132 views
0

美好的一天!執行打開新窗口並執行Javascript

是否有可能當我從父窗口打開新窗口時,JavaScript會在新窗口上執行?

例如,如果新窗口完全加載,文本字段將更改值。

感謝

+0

腳本應該可以,只要這兩個窗口是完全相同的主機名父母和孩子之間的窗口進行交互。 – Jay 2012-08-10 09:49:11

+0

是的..它是相同的域和主機..我怎麼能做到這一點? – user1578707 2012-08-11 08:05:41

回答

0

得到新窗口的onLoad()事件的參數父窗口,通知新窗口已經被加載。

我希望這能解決您的問題。

0

下面是的一個示例,將函數放入子窗口中,然後讓子窗口運行它。 showTitle函數將只顯示當前文檔標題。子頁面將等待特定功能並在到達時調用它。

parent.html:

<html> 
<head> 
<title>parent</title> 
</head> 
<body> 
<script> 
function showTitle() { 
alert('Page Title = '+this.document.title); 
} 
function childLoaded() { 
showTitle(); 
var childWnd=document.getElementById('fchild').contentWindow; 
if (!childWnd) return; 
childWnd.newFunc=showTitle; 
} 
</script> 
parent<br /> 
<iframe id=fchild src="child.html" width=300 height=300 onload="childLoaded()"></iframe> 
</body> 
</html> 

child.html:

<html> 
<head> 
<title>child</title> 
</head> 
<body> 
<script> 
var waiter,newFunc=null; 
function waitFunc() { 
if (newFunc) { 
    clearInterval(waiter); 
    newFunc(); 
} 
} 
waiter=setInterval(waitFunc, 1000); 
</script> 
child 
</body> 
</html> 
相關問題