Last active
February 25, 2016 09:43
-
-
Save ediamin/3c856deaf6cf7cf2e486 to your computer and use it in GitHub Desktop.
On click open same url in two tabs
This file contains hidden or 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
<!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