JavaScript-program för att få den aktuella webbadressen

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.hrefegendom och document.URLegendom för att hämta webbadressen till den aktuella sidan.

Både egenskaperna window.location.hrefoch document.URLegenskaperna returnerar webbadressen till den aktuella sidan.

Intressanta artiklar...