2011-08-17 62 views
1

我希望能夠使用window.open打開一個彈出窗口,並訂閱opener中彈出窗口的頁面事件(onload等)。所以我想在我的opener(父頁面)中執行一個方法,當彈出窗口的onload或者準備好觸發時。這可能使用普通的js或jQuery?請不要問我爲什麼要這樣做 - 這可以爲我解決很多問題。Javascript - 從另一個頁面訂閱頁面的事件

回答

1

第一頁(x.html):

<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
<script> 
    var w = window.open('y.html', 'w'); 
    w.document.getElementById('target').onclick = function() { alert('!'); }; 
</script> 
</body> 
</html> 

第二頁(y.html):

<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
    <button id="target">target</button> 
</body> 
</html> 

對我的作品......

+0

你真的確定碼加工! – Fatih

+0

對不起,不工作的FF 5.0.1 – Fatih

+0

是的,當然,甚至嘗試在演示頁面上。 – Fatih

相關問題