Skip to content

Instantly share code, notes, and snippets.

@okiwan
Created April 17, 2014 07:44
Show Gist options
  • Save okiwan/10961868 to your computer and use it in GitHub Desktop.
Save okiwan/10961868 to your computer and use it in GitHub Desktop.
Open links in a background tab (tested on Chrome 34 only)
<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