2010-08-30 158 views
0

我正在尝试使用window.open在新窗口(选项卡)中打开一个位置。它不适用于Chrome。首先,我尝试了window.open(url,name),但这并不奏效,但是这适用于其他任何浏览器。然后我用这样的事情,window.open不工作在铬6

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

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

+0

微小的弹出式窗口拦截器图标跳过了我的眼睛。谢谢你们...... :) – Harsha 2010-09-01 06:10:13

回答

4

你确定你的弹出窗口没有被阻止吗?大多数弹出式窗口不会响应用户事件而被阻止。我将window.open(“google.com”,“_blank”)输入到控制台中,并且我在url栏上获得了被阻止的窗口

1

做这样的

window.open(url, "_blank"); 

记住,第二个参数是类似于一个锚标记的target属性。

+0

彼得,这是不工作:(。我没有使用锚标记,它的闪光点击时,该网址必须在新标签中打开。 – Harsha 2010-08-30 14:55:20

+1

Chrome可能阻止它,然后。 – 2010-08-30 15:10:41

0

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

<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"); 
} 
</script> 
</head> 
<body> 
</body> 
</html> 
0

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

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

从Redirect.aspx页面重定向到QS指定的网址...

这工作一种享受,我使用Chrome挡住了我的新窗口。

+0

我没有让本地文件被弹出窗口阻止程序忽略,即在/some-file.php打开文件仍会触发Chrome的弹出窗口阻止程序。 – 2012-06-20 01:59:13