我正在尝试创建一个按钮,一旦单击,将在弹出窗口中打开一个本地HTML文件。当我运行代码时,按钮显示在我的页面上,但是当我点击它时,没有任何反应。这是我现在的代码:
<html>
<head>
<title>Positioning a Popup Window in the Center of the Window</title>
</head>
<body>
<script language="JavaScript">
function openWindow() {
var w = 480, h = 340;
if (document.getElementById) {
w = screen.availWidth;
h = screen.availHeight;
}
var popW = 300, popH = 200;
var leftPos = (w-popW)/2;
var topPos = (h-popH)/2;
msgWindow = window.open('separateHTML.html','popup','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ', scrollbars=yes');
</script>
<form>
<input type="button" onClick="openWindow()" value="Click Me">
</form>
</body>
</html>
URL“separateHTML.html”指的是我在与此HTML文件相同的目录中的另一个HTML文件。为什么按钮不会转到'separateHTML.html'?
答案 0 :(得分:2)
您忘记在功能“}”
的末尾关闭括号答案 1 :(得分:0)
也许是这样的?
<button onclick="myFunction()">PopUp Window</button>
<script>
function myFunction() {
window.open("separateHTML.html", "_blank", top=300, left=200, width=480, height=340");
}
</script>