开发者

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

开发者 https://www.devze.com 2023-03-28 23:57 出处:网络
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

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

精彩评论

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