开发者

Javascript - subscribe to an event of a page from another page

I want to be able to open a popup using window.open and subscribe to page events (onload etc) of the popup in the opener. So i'd want a method in my opener (parent page) to execute when the popup's onload or ready fires. Is this possible using plain js or jquery? Pls don't ask me why i want 开发者_C百科to do this - this can solve a lot of issues for me.


First page (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>

Second page (y.html):

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

Works for me...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜