I have a link and want to redirect them with JavaScript to another URL. I have it working for left click, but not when the user Middle-Click or Right-Click -> Open in New Tab/Window. How would I get this to work for middle/right click flows?
Codepen doesn't display the href
behavior very well
http://codepen.io/anon/pen/OyeGqv
$('a').on('click', function(e) {
e.preventDefault();
window.location.href = 'http://www.google.ca'; //does not work for middle/right click
});
<a href="#">link</a>
I have tried listening to the mousedown
event instead of click
, but I was only able to re-direct the current window. The new window/tab that opened returned the incorrect URL of #
instead of www.google.ca
.