Open links in another window by setting the <a> target attribute - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Open links in another window by setting the <a> target attribute

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(e) {/*from   www. j  a  v a2  s  .c  o m*/
    var links = document.getElementsByTagName('a');
    for (var i = 0; i < links.length; i++) {
        links[i].target = '_blank';
    }
}

      </script> 
   </head> 
   <body> 
      <a href="http://www.example.com/">Link 1</a> 
      <a href="http://www.example.com/">Link 2</a> 
      <a href="http://www.example.com/">Link 3</a>  
   </body>
</html>

Related Tutorials