Last active
August 29, 2015 14:22
-
-
Save baumannsven/505ed5fc39f334a508b2 to your computer and use it in GitHub Desktop.
open links with jquery
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
$(document).ready(function () { | |
$('.box').click(function (handler) { | |
if ($(this).find('a').length > 0) { | |
//best cross browser way for trigger links | |
var link = $(this).find('a')[0]; | |
// open links with target _blank or ctrl/cmd pressed in a new tab | |
// open links with shift key in a new window | |
if (link.target != '' | |
|| handler.metaKey | |
|| handler.ctrlKey | |
|| handler.shiftKey | |
) { | |
var open = window.open(link.href, link.target); | |
open.location; | |
return true; | |
} | |
location.href = link.href; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment