开发者

Javascript access to other page

开发者 https://www.devze.com 2023-03-29 03:41 出处:网络
Can I have access from javascript on one page to elements on other page the script has created before? Something like this:

Can I have access from javascript on one page to elements on other page the script has created before? Something like this:

var win=window.open("http://www.ftwars.com/battle",'myWindow');
win.document.getElementById('center').onClick()开发者_运维百科;


Simply yes - you can , via variable reference, you cannot reach reference if you not created it in your javascript


You are correct. From the context you have given above, win is like any other object.


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>
0

精彩评论

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