Created
April 17, 2014 07:44
-
-
Save okiwan/10961868 to your computer and use it in GitHub Desktop.
Open links in a background tab (tested on Chrome 34 only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<ul id="links"> | |
<li><a href="http://sega.co.jp/">SEGA</a></li> | |
<li><a href="http://www.yahoo.com/">Yahoo!</a></li> | |
</ul> | |
<a href="#" onclick="openAll();return false;">Click here</a> | |
<script type="text/javascript"> | |
function openAll() { | |
var a = document.createElement('a'); | |
var e = document.getElementById('links').children; | |
for(i = 0; i < e.length; i++) { | |
a.href = e[i].children[0].getAttribute('href'); | |
var evt = document.createEvent("MouseEvents"); | |
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null); | |
a.dispatchEvent(evt); | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment