Menü Schließen

JavaScript – Host – Domain – Port und Adressinformation abfragen

Java Logo

JavaScript Snipe zum Objekt location

Nachfolgend ein paar kurze Snipes / Schnipsel zur Abfrage der URL inkl. Host, Hostname, Link, Pathname, Port und Protokoll mittels JavaScript:

Grundsätzlich ist alles im Object location hinterlegt:

Beispiel für das Objekt location:

location = {
host: “taste-of-it.de”,
hostname: “taste-of-it.de”,
href: “http://taste-of-it.de/javascript-host-domain-port-und-adressinformation-abfragen”,
pathname: “/javascript-host-domain-port-und-adressinformation-abfragen”,
port: “”,
protocol: “http:”
}

Beispiel für das Anzeigen der einzelnen Elemente des Objekts location:

# alert(“document.URL : “+document.URL);
-> document.URL : http://localhost:8080/testseite/site?view=admin
# alert(“document.location.href : “+document.location.href);
->document.location.href : http://localhost:8080/testseite/site?view=admin
#alert(“document.location.origin : “+document.location.origin);
->document.location.origin : http://localhost:8080
#alert(“document.location.hostname : “+document.location.hostname);
->document.location.hostname : localhost
#alert(“document.location.host : “+document.location.host);
->document.location.host : localhost:8080
#alert(“document.location.pathname : “+document.location.pathname);
->document.location.pathname : /testseite/site

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert