开发者

Javascript access to other page

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜