0

<a href='#' onclick="loadpage();">[RANDOM PAGE]</a>

I call the following function on click.

function loadpage(){
$.ajax
({
type: "POST",
url: "fetchpage.php",
data: "showpage=1",
success: function(msg)
{
window.open(msg);
}
});
}

The ajax call returns a URL, msg which should be opened in a new tab.

Rápli András
  • 3,869
  • 1
  • 35
  • 55
  • 2
    possible duplicate of [Programmatically open new pages on Tabs](http://stackoverflow.com/questions/427479/programmatically-open-new-pages-on-tabs) – Evan Davis Sep 26 '13 at 14:55

4 Answers4

2

I think it depends on the browser config. JS can't control it.

Max Wong
  • 316
  • 2
  • 9
0

How about :

$('body').append('<a id="newTab" target="_new" href="http://......></a>');
$('#newTab').click();
andrew
  • 9,313
  • 7
  • 30
  • 61
0

You can not do this. Even if you can, all the browser does not works! IE!!!

Garfield
  • 2,487
  • 4
  • 31
  • 54
0

I found a way to do it which works on all modern browsers (including IE7+):

function loadpage(a){
$.ajax
({
type: "POST",
url: "fetchpage.php",
data: "showpage=1",
success: function(msg)
{
a.href=msg;
a.rel='nofollow';
a.target='_blank';
}
});
}

and

<a href='#' onmouseover="loadpage(this);">[RANDOM PAGE]</a>
Rápli András
  • 3,869
  • 1
  • 35
  • 55