Archive for JavaScript

JavaScript – Get URL

Friday, April 10th, 2009

JavaScript can get full URL of webpage. Server side script is not required if you are looking for URL of browser. JavaScript have function to get full URL with location object.

window.location object return full path of webpage opened on web browser and manipulate with split function.

Location object returns with host name, port, protocol (http or https), file name and query string with variable name and value in escaped string.

URL string can further use for making new URL or modification of URL with split array and href of location object.

window.location

 

window.location.href

full example code

<html>
<head>
<title>Javascript get url</title>
</head>

<body>
<script>
document.write(document.location.href)
</script>
</body>
</html>

Demo