【发布时间】:2014-12-19 20:59:13
【问题描述】:
我正在尝试单击一个按钮,并调用该函数以使用 window.open() 方法打开一个已经存在的新窗口,同时我想使用更改新窗口的内容document.getElementById('para').innerHTML="New";但我无法访问和更改内容。
<!DOCTYPE html>
<html>
<body>
<p>I want to click on the button and opens a new window, can change the new window's text "old"to the word "New", but I can't access the new window</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var myWindow = window.open("newWindow.html", "MsgWindow", "width=200, height=100");
myWindow.document.getElementById('para').innerHTML="New";
}
</script>
</body>
</html>
下面是我尝试访问和操作的新窗口
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<p id="para">Old</p>
</body>
</html>
非常感谢!
惠
【问题讨论】:
标签: javascript