![](/img/trans.png)
[英]window.open() inside multiple if conditions doesn't work in javascript
[英]window.open() doesn't work correctly inside a JS function
我试图为我的网站创建一个更新列表,以便当我单击相关更新时,将打开一个新的附加小html窗口,我将看到完整的更新内容。
这是我写的代码:
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="script.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body ng-app="myApp">
<p ng-controller="updatesCtrl">
<span ng-repeat="x in updates">
<a href="updateWindow.html" onclick="showUpdate(x.title,x.update)">● {{x.title}}</a>
<br><br>
</span>
</p>
<script>updates();</script>
</body>
</html>
script.js:
function updates(){
angular.module('myApp', []).controller('updatesCtrl', function($scope) {
$scope.updates = [
{title:"update1",update:"update1 content"},
{title:"update2",update:"update2 content"}
];
});
}
function showUpdate(title, update){
var win=window.open('updateWindow.html','newwindow','width=600, height=350');
win.document.getElementById("title").innerHTML=title;
win.document.getElementById("update").innerHTML=update;
return false;
}
updateWindow.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<h1 id="title"></h1>
<p id="update"></p>
</body>
</html>
我在这里有几个问题:
1.当我单击更新链接时,更新窗口替换了主页(index.html)窗口,并且也是一个完整页面。
2.尽管我编写了一个脚本,假设未在这些位置输入html内容,但updateWindow的<h1>
和<p>
并未进行任何更改。
我不明白为什么我没有得到这段代码期望的结果。 特别是,我不明白第一个问题:如果我只尝试用以下内容替换index.html
的onclick
内容: "window.open('updateWindow.html','newwindow','width=600, height=350'); return false;"
-我得到了一个新的附加窗口,其尺寸比预期的要小(我不会在此窗口中获取更新内容,但至少可以解决我的第一个问题)。
我的代码有什么问题?
尝试使用window.open('updateWindow.html','_blank','width=600, height=350');
代替
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.