Get current URL of each Web Page using JavaScript

When it is needed to display the current unique URL of each page within a site you can try the following script:

<script type="text/javascript" >
document.write(location.href);
</script>

For example, if we are browsing this page

http://www.scriptiny.com/category/javascript/

This script will generate/print:

http://www.scriptiny.com/category/javascript/

Now if a site with 50 pages requires to show current URL in each page, just put this piece of script into master page. It will allow to avoid manual doing for each page.
If it is required to display the current URL as hyperlink, try this one

 <script type="text/javascript" >

document.write('<a href="' + location.href +'">');
document.write(location.href);
document.write('</a>');

</script>

This will generate/print:
http://www.scriptiny.com/category/javascript/

This entry was posted in Other, Syndicated. Bookmark the permalink.

Comments are closed.