JS – Location Href – Pathname – Assign

Get Location Href and Get Location Pathname:

<!DOCTYPE html>
<html>
<body>

<script>
// Location Href
document.write("Location Href: " + location.href + "<br>");
// Location Pathname
document.write("Location Pathname: " + location.pathname);

</script>

</body>
</html>

Sample result on web:
Location Href: http://www.lucedigitale.com/content/sample.html
Location Pathname: /content/sample.html

Sample result on local:
Location Href: file:///C:/Users/Utente/Desktop/content/sample.html
Location Pathname: /C:/Users/Utente/Desktop/content/sample.html

Load a new document inside current window:

<!DOCTYPE html>
<html>
<head>
<script>
function newDoc()
  {
  window.location.assign("http://www.lucedigitale.com")
  }
</script>
</head>
<body>

<input type="button" value="Load new document" onclick="newDoc()">

</body>
</html>

My official WebSite >