<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Obtener url con javascript</title><script type="text/javascript">alert(location.href);onload=function(){ document.getElementById('dir').value = location.href;}</script></head> <body> <input type="text" id="dir" value="" size="100" /></body></html>
<html> <head> <title>Haciendo uso de location</title> </head> <body> <script language="JavaScript"> <!-- document.write("Location <b>href</b>: " + location.href + "<br>"); document.write("Location <b>host</b>: " + location.host + "<br>"); document.write("Location <b>hostname</b>: " + location.hostname + "<br>"); document.write("Location <b>pathname</b>: " + location.pathname + "<br>"); document.write("Location <b>port</b>: " + location.port + "<br>"); document.write("Location <b>protocol</b>: " + location.protocol + "<br>"); //--> </script> </body> </html>