Stop <a> click event without holding control key - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Stop <a> click event without holding control key

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function doAjax(e) {/*  ww  w .j  a  v  a 2  s.  co  m*/
    if (!e) e = window.event;
    if (!e.ctrlKey) {
        console.log("Ajax code here");
        return false;
    }
}

      </script> 
   </head> 
   <body>
       Here is a 
      <a href="/link/location" onclick="return doAjax(event);">link</a>  
   </body>
</html>

Related Tutorials