How can I open new browser tabs without focus on them?
(Like clicking on the middle button on a mouse.)
Code:
$("html").on "click", ->
window.open('http://google.com')
$(document).focus()
And I want to still be on the current site.
How can I open new browser tabs without focus on them?
(Like clicking on the middle button on a mouse.)
Code:
$("html").on "click", ->
window.open('http://google.com')
$(document).focus()
And I want to still be on the current site.
This answer details what seems to be a legitimate way to open a tab in the background. Converting the answer to CoffeeScript, I get:
openNewBackgroundTab = ->
a = document.createElement("a")
a.href = "http://www.google.com/"
evt = document.createEvent("MouseEvents")
#the tenth parameter of initMouseEvent sets ctrl key
evt.initMouseEvent "click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null
a.dispatchEvent evt
return