Skip to main content
Fixed the weird syntax highlighting (as a result, the diff looks more extensive than it really is - use view "Side-by-side Markdown" to compare).
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

This is a trick,

function openInNewTab(url) { window.open(url, '_blank').focus(); } // Or just window.open(url, '_blank').focus(); 
function openInNewTab(url) { window.open(url, '_blank').focus(); } // Or just window.open(url, '_blank').focus(); 

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="openInNewTab('www.test.com');">Something To Click On</div> 
<div onclick="openInNewTab('www.test.com');">Something To Click On</div> 

Reference: Open a URL in a new tab using JavaScript

This is a trick,

function openInNewTab(url) { window.open(url, '_blank').focus(); } // Or just window.open(url, '_blank').focus(); 

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="openInNewTab('www.test.com');">Something To Click On</div> 

Reference: Open a URL in a new tab using JavaScript

This is a trick,

function openInNewTab(url) { window.open(url, '_blank').focus(); } // Or just window.open(url, '_blank').focus(); 

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="openInNewTab('www.test.com');">Something To Click On</div> 

Reference: Open a URL in a new tab using JavaScript

Dressed the naked link, etc.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

This is a trick,

function openInNewTab(url) {   window.open(url, '_blank').focus(); } //or Or just window.open(url, '_blank').focus(); 

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="openInNewTab('www.test.com');">Something To Click On</div> 

http://www.tutsplanet.com/open-url-new-tab-using-javascript/ Reference: Open a URL in a new tab using JavaScript

This is a trick,

function openInNewTab(url) { window.open(url, '_blank').focus(); } //or just window.open(url, '_blank').focus(); 

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="openInNewTab('www.test.com');">Something To Click On</div> 

http://www.tutsplanet.com/open-url-new-tab-using-javascript/

This is a trick,

function openInNewTab(url) {   window.open(url, '_blank').focus(); } // Or just window.open(url, '_blank').focus(); 

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="openInNewTab('www.test.com');">Something To Click On</div> 

Reference: Open a URL in a new tab using JavaScript

This is a trick,

function openInNewTab(url) {   var win = window.open(url, '_blank').focus(); } //or just window.open(url, win'_blank').focus(); } 

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="openInNewTab('www.test.com');">Something To Click On</div> 

http://www.tutsplanet.com/open-url-new-tab-using-javascript/

This is a trick,

function openInNewTab(url) {   var win = window.open(url, '_blank'); win.focus(); } 

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="openInNewTab('www.test.com');">Something To Click On</div> 

http://www.tutsplanet.com/open-url-new-tab-using-javascript/

This is a trick,

function openInNewTab(url) { window.open(url, '_blank').focus(); } //or just window.open(url, '_blank').focus(); 

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="openInNewTab('www.test.com');">Something To Click On</div> 

http://www.tutsplanet.com/open-url-new-tab-using-javascript/

deleted 4 characters in body
Source Link
Duke
  • 37.3k
  • 13
  • 57
  • 74
Loading
added 1 character in body
Source Link
Duke
  • 37.3k
  • 13
  • 57
  • 74
Loading
added 14 characters in body
Source Link
Vikrant
  • 5.1k
  • 18
  • 53
  • 77
Loading
It JavaScript it is convention to only capitalize constructor functions
Source Link
Useless Code
  • 12.5k
  • 5
  • 37
  • 42
Loading
added 69 characters in body
Source Link
Duke
  • 37.3k
  • 13
  • 57
  • 74
Loading
Rollback to Revision 4
Source Link
user456814
user456814
Loading
Rollback to Revision 2
Source Link
user456814
user456814
Loading
Formatted in conventional JavaScript.
Source Link
user456814
user456814
Loading
added 282 characters in body
Source Link
FlavorScape
  • 14.5k
  • 13
  • 79
  • 124
Loading
added 5 characters in body
Source Link
Duke
  • 37.3k
  • 13
  • 57
  • 74
Loading
Source Link
Duke
  • 37.3k
  • 13
  • 57
  • 74
Loading