Open URL in a new window in <a> click event - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Open URL in a new window in <a> click event

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
        window.onload = function(){
            if (!document.getElementById) 
               return false;/*www.  j a  va2s  .c  o  m*/
            var popupLink = document.getElementById("popup");
            popupLink.onclick = function(){
                  window.open(this.getAttribute("href"));
                  return false;
            }
        };

      </script> 
   </head> 
   <body> 
      <a id="popup" href="http://java2s.com/">click me</a>  
   </body>
</html>

Related Tutorials