Obtenez l'URL actuelle avec JavaScript

Mots clés : javascripturl

meilleur 4 Réponses Obtenez l'URL actuelle avec JavaScript

vote vote

91

window.location.href 
document.URL 
vote vote

90

var currentLocation = window.location; 
<protocol>//<hostname>:<port>/<pathname><search><hash> 
vote vote

72

window.location.href 
vote vote

70

window.location.href; // use it in the console of this page will return // http://stackoverflow.com/questions/1034621/get-current-url-in-web-browser" 
document.getElementById("root").innerHTML = "The full URL of this page is:<br>" + window.location.href;
<!DOCTYPE html>  <html>    <body>    <h2>JavaScript</h2>    <h3>The window.location.href</h3>    <p id="root"></p>  </body>    </html>
window.location.protocol + '//' + window.location.hostname + window.location.pathname + window.location.hash === window.location.href;     //true 
location.protocol  location.hostname  location.pathname  location.hash  location.href 

Questions similaires