Now I have the following code:
<script> $("#clickme").click(function(){ $("#clicker").click(); }); </script> <div id="clickme" style="height:20em; width:20em;"> <a id="clicker" href="http://www.google.com"> Link </a> </div>
Effectively, if you click anywhere on the background of the div, Javascript will simulate a click on the actual link and lead you to the landing page.
However, this does not work so well when you try ctrl-click, since the browser will not open a new tab and instead simply loads the url into the current window.
Instead of this behavior, I want to have the usual browser behavior (i.e. open a new tab, do not change the current window for clicking Ctrl) when clicking on the background. Is there a way to do this in Javascript / jQuery?
I would rather not try to detect the "ctrl" key press - there are several similar cases, and I would rather have a solution that solves everything, and not try to catch every edge case like this.
source share