Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
My example can open many links in tabs, not in new windows. Why need this and do not use Because there is the problem - if you call once it will open new tab or window(it depends of browser), if will call two or more times - first will open like tab/window and all next in the new window only. The individual b…
<!DOCTYPE html>
<meta charset="utf-8">
<title>Open 3 tabs</title>
<script src=""></script>
<div id="hidden_div"></div>
var urls = ['','',''],
isFF = navigator.userAgent.toLowerCase().indexOf('firefox') > 0,
isIE = /*@cc_on!@*/false,
hiddenArea = $('#hidden_div').hide();
function emulateClick(element){
var evt = element.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, element.ownerDocument.defaultView, 1, 0, 0, 0, 0, true, false, false, true, 0, null);
if (document.createEventObject){
element.fireEvent('onclick', evt)
} else{
if (isFF || isIE) {
$.each(urls, function (index, url) {
var $form = $('<form>', {
"target" : "_blank",
"action" : url,
"method" : "post",
"name" : "form" + index
hiddenArea.append($form);//need to be attached to DOM
} else {
$.each(urls, function (index, url) {
var $link = $('<a>', {
"target" : "_blank",
"href" : url

This comment has been minimized.

Copy link
Owner Author

@frontenddeveloping frontenddeveloping commented Nov 21, 2013

But don't rely on this solution which open new tabs in 100% cases. In some browser user can configure this option - open in new tab or window all links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment