Event click handler on href <a> tag - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Event click handler on href <a> tag

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 doWork(){/*from  ww  w. j a v a  2 s.  com*/
          console.log("redirecting");
          //... do your works
          return true; // then return true to redirect
    }

      </script> 
   </head> 
   <body> 
      <a href="http://www.google.com" target="_new" onclick="return doWork();">Click to redirect</a>  
   </body>
</html>

Related Tutorials