location.href
We can get the full URL of the current page by using location object , Here is the syntax.
location.href
Sample code is here.
<script language='JavaScript' type='text/JavaScript'>
<!--
document.write(location.href);
//-->
</script>
The output is here
Path of to the script root
We can get path of the URL upto the root of the page by using slice and lastIndexOf function
Here it is
<script>
var path=location.href;
var ind=path.lastIndexOf("/");
var root_path=path.slice(0,ind);
document.write(root_path);
</script>
Output is here
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
plus2net.com
|