Skip to content

Instantly share code, notes, and snippets.

@ediamin
Last active February 25, 2016 09:43
Show Gist options
  • Save ediamin/3c856deaf6cf7cf2e486 to your computer and use it in GitHub Desktop.
Save ediamin/3c856deaf6cf7cf2e486 to your computer and use it in GitHub Desktop.
On click open same url in two tabs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://localhost/unique-dev/wp-includes/js/jquery/jquery.js?ver=1.11.3"></script>
</head>
<body>
<a href="http://google.com" target="_blank">Go to google</a>
<script>
;(function($) {
'use strict';
$('a').on('click', function (e) {
e.preventDefault();
var clicked = $(this).data('clicked') ? parseInt($(this).data('clicked')) : 1,
url = $(this).attr('href');
if (clicked <= 2) {
window.open(url, '_blank');
$(this).data('clicked', ++clicked);
$(this).trigger('click');
}
});
})(jQuery);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment