- Back to Home »
- HTML , Javascript , jQuery »
Posted by : Jebastin
Sunday, 15 December 2013
Get current HTML page Title and URL with jQuery and Javascript.
Current Page Title:
jQuery:
- var title = $(document).find("title").text();
- (or)
- var title = $('title').text();
- (or)
- var title = $(document).attr('title');
Javascript:
- var title = document.getElementsByTagName("title")[0].innerHTML;
Current Page URL:
jQuery:
- var url = $(location).attr('href');
- (or)
- var url = $(location).attr('pathname');
Javascript:
- var url = document.URL
- (or)
- var url = window.location.href
- (or)
- var url = window.location.pathname;