10

I'm making a personal script to search google in another language and I've got a url that I've passed from a php script. I want to use jquery to open that url in a new tab (only in google chrome).

I tried:

  window.open("http://localhost/123", '_blank');

It unfortunately Opens in a new window in google chrome, which is unfortunately the only browser that's light enough to use on my computer. I don't seem to have any success googling it so any advice would be much appreciated.

Thanks Sam

EDITED: Sorry if your not meant to edit like this but my new question is (I should probably ask it somewhere else):

How to edit google chromes config to open a new tab instead of a window when window.open("href", "_blank") is called?

killkrazy
  • 127
  • 1
  • 1
  • 6
  • it works if I use a link a href="asd" target="_blank", I'm just about to look on the google website for more info – killkrazy Oct 23 '11 at 16:11
  • 2
    possible duplicate of [How do you open a new tab in chrome using HTML/JS?](http://stackoverflow.com/questions/5495328/how-do-you-open-a-new-tab-in-chrome-using-html-js) – Jon Oct 23 '11 at 16:12
  • How would I go about changing my google chrome to allow window open to go into a new tab? – killkrazy Oct 23 '11 at 16:17
  • Also possible duplicate: [Programmatically open new pages on Tabs](http://stackoverflow.com/questions/427479/programmatically-open-new-pages-on-tabs) – Kevin Ji Oct 23 '11 at 17:36

3 Answers3

4

You can't directly control this, because it can be configured by the user. You might try "_newtab" which might work for Firefox but really you shouldn't rely on a new tab being opened. The user may have their browser settings set to open a new tab when a popup window is opened or it may show up as a popup. It just all depends on the browser settings.

Adam
  • 4,590
  • 10
  • 51
  • 84
-1
<a href="#" onclick="newTab();">Test</a>

<script>
  function newTab()
   {
     window.open('www.google.com', '_blank', 'toolbar=0,location=0,menubar=0');
   }
</script>
Irshad Khan
  • 5,670
  • 2
  • 44
  • 39
  • in that case, it would've been much better to use `Test` than inline script. Correct me if I am wrong, but your code will give a "pop-up blocked" error. – R.D. Oct 23 '14 at 16:56
  • I used this to block Toolbar and menubar on new window of Browser – Irshad Khan Feb 12 '15 at 08:00
-6
`$(document).ready(function() {
   $('#NewTab').click(function() {
        $(this).target = "_blank";
        window.open($(this).prop('href'));
        return false;
   });
});`

http://franglyaj.blogspot.in/2012/12/jquery-open-url-in-new-tab-using.html
frangly
  • 162
  • 7