How do I open a new browser tab from JavaScript?

How do I write a JavaScript function that opens a new browser tab at a specified URL? I know how to do this in In HTML using a link with target = "_blank", but in my case, I need to do it from a JS function.

thank

+2


source to share


3 answers


You cannot specify what to open in a "new tab", but if you have a tabbed browser, this behavior is configurable. For example, I believe Firefox has this default behavior

See Tools -> Options -> Tabs -> check the box "open new windows in a new tab"



The following JavaScript will work for you

<script>
    window.open("http://www.google.com", "google"); 
</script>

      

0


source


You can not. Javascript doesn't have native tab support because not all browsers that support Javascript have tabs at all (IE6 think). You can open the window in most cases (although it is of course possible that the popup is blocked).



Some browsers may display these new windows as tabs. I believe Opera does it.

0


source


<script>
  window.open("http://stackoverflow.com/", "SO");
</script>

      

More information here .

0


source







All Articles