关于javascript:window.open在Chrome 6中不起作用

window.open not working in chrome 6

我正在尝试使用window.open在新窗口(选项卡)中打开位置。 它不适用于Chrome。 首先,我尝试使用window.open(url,name),这没有用,但是在其他所有浏览器中都可以用。 然后我用了这样的东西

1
2
3
var w = window.open("about:blank");
w.opener = null;
w.document.location = url;

这会在同一选项卡中打开URL,但不会在单独的选项卡中打开URL。


您确定您的弹出窗口没有被阻止吗? 大多数未响应用户事件发生的弹出窗口将被阻止。 我在控制台中输入window.open(" google.com"," _blank"),然后在网址栏上看到了被阻止的窗口


像这样做

1
window.open( url,"_blank" );

请记住,第二个参数类似于定位标记的target属性。


创建一个重定向页(例如Redirect.aspx)。

1
window.open('Redirect.aspx?URL=http://www.google.com', '_blank');

在Redirect.aspx页面上,重定向到QS中指定的URL。

Chrome阻止了我的新窗口,这对我来说是一种享受。


试试这个。 在IE8中工作,在弹出窗口被阻止时在FF中失败

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<html>
<head>
<script type="text/javascript">
if(typeof HTMLElement!='undefined'&&!HTMLElement.prototype.click)
HTMLElement.prototype.click=function(){ // event by Jason Karl Davis
var evt = this.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
}
function loadAndClick(url,target) {
  var lnk = document.createElement("a");
  lnk.href=url;
  lnk.target=target||"_blank"
  lnk.id="myLink"
  lnk.onclick=function() {
    var w = window.open(this.href,this.target);
    return (w)?false:true;
  }
  document.body.appendChild(lnk);
  document.getElementById('myLink').click();
//  lnk.click();
}
window.onload=function() { // or call getURL("javascript:loadAndClick('http://www.google.com')");
  loadAndClick("http://www.google.com");
}  

</head>
<body>
</body>
</html>