I det här exemplet lär du dig att skriva ett JavaScript-program som får den aktuella URL: n.
Exempel: Hämta den aktuella webbadressen
// program to get the URL const url1 = window.location.href; const url2 = document.URL; console.log(url1); console.log(url2);
Produktion
https://www.google.com/ https://www.google.com/
I ovanstående program används window.location.href
egendom och document.URL
egendom för att hämta webbadressen till den aktuella sidan.
Både egenskaperna window.location.href
och document.URL
egenskaperna returnerar webbadressen till den aktuella sidan.