Harsha
Harsha

Reputation: 737

window.open not working in chrome 6

I am trying to open a location in new window(tab) using window.open. It is not working in chrome. First I tried with window.open(url,name), this did not work, however this works in every other browser. Then I used something like this,

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

This opens the url in same tab but not in separate tab.

Upvotes: 0

Views: 7787

Answers (4)

tribe84
tribe84

Reputation: 5632

Create a redirect page (for example Redirect.aspx).

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

From the Redirect.aspx page, redirect to the URL specified in the QS...

This worked a treat for me with Chrome blocking my new windows.

Upvotes: 0

mplungjan
mplungjan

Reputation: 178375

Try this. Works in IE8, fails in FF when popups are blocked

<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>

Upvotes: 0

Ruan Mendes
Ruan Mendes

Reputation: 92314

Are you sure your popup is not being blocked? Most popup windows that didn't happen in response to a user event will get blocked. I typed window.open("google.com", "_blank") into the console and I got the blocked window on the url bar

Upvotes: 4

Peter Bailey
Peter Bailey

Reputation: 105916

Do it like this

window.open( url, "_blank" );

Remember, the 2nd parameter is analogous to an anchor tag's target attribute.

Upvotes: 1

Related Questions