“Emplacement de la fenêtre JavaScript” Réponses codées

javascript obtient une URL actuelle

var currentUrl = window.location.href;
Grepper

window.href

//its actually 
window.location.href = "/App/Home"
//or
window.location.href = "https://www.google.com/"
Confused Penguin

JavaScript Get Domain

window.location.hostname
Friendly Hawk

Emplacement de la fenêtre tout web

var url = new URL("http://aaa.bbb.ccc.com/asdf/asdf/sadf.aspx?blah");
console.log(url.protocol);  // "http:"
console.log(url.hostname);  // "aaa.bbb.ccc.com"
console.log(url.pathname);  // "/asdf/asdf/sadf.aspx"
console.log(url.search);  
Antoniotonio

Emplacement de la fenêtre

document.getElementById("demo").innerHTML = 
"The full URL of this page is:<br>" + window.location.href;
//Result
//The full URL of this page is: https://www.w3schools.com/js/tryit.asp?filename=tryjs_loc_href

document.getElementById("demo").innerHTML =
"Page hostname is " + window.location.hostname;
//Result
//Page hostname is www.w3schools.com

document.getElementById("demo").innerHTML =
"Page path is " + window.location.pathname;
//Result
//Page path is /js/js_window_location.asp
Shadow

Emplacement de la fenêtre JavaScript

document.getElementById("demo").innerHTML =
"Page location is " + window.location.href;
naly moslih

Réponses similaires à “Emplacement de la fenêtre JavaScript”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code