Convert location.href URL to Anchor link - Javascript Browser Object Model

Javascript examples for Browser Object Model:Location

Description

Convert location.href URL to Anchor link

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(){//from   w  ww  . j a v a2s  . co  m
document.getElementById("myAnchor").setAttribute("href", window.location.href);

var loc = document.getElementById("myAnchor").getAttribute("href");

var t = document.createTextNode(loc);

document.getElementById("myAnchor").appendChild(t);
    }

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

Related Tutorials