Skip to content

Instantly share code, notes, and snippets.

@sentientwaffle
Created November 18, 2012 17:20
Show Gist options
  • Save sentientwaffle/4106332 to your computer and use it in GitHub Desktop.
Save sentientwaffle/4106332 to your computer and use it in GitHub Desktop.
Open link in new tab
// Source: http://jsfiddle.net/3ZmvS/5/
function openNewTab(url) {
var a = document.createElement("a")
, ev = document.createEvent("MouseEvents")
a.href = url
ev.initMouseEvent( "click", true, true, window
, 0, 0, 0, 0, 0, true, false
, false, false, 0, null )
a.dispatchEvent(ev)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment