Skip to content

Instantly share code, notes, and snippets.

@baumannsven
Last active August 29, 2015 14:22
Show Gist options
  • Save baumannsven/505ed5fc39f334a508b2 to your computer and use it in GitHub Desktop.
Save baumannsven/505ed5fc39f334a508b2 to your computer and use it in GitHub Desktop.
open links with jquery
$(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