Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get URL, get Title by Javascript not jQuery

Does anyone know how to get url and title of the current page by using Javascript without jQuery!?


<script type="text/javascript">
  var title = document.getElementsByTagName('title')[0].innerHTML;
  var url = document.location.href
  socializ(encodeURIComponent('+href+'),encodeURIComponent('+title+'))
</script>

Just doesn't work.. need help...

like image 863
Bato Dor Avatar asked Dec 06 '10 16:12

Bato Dor


2 Answers

The location object is what you're after for the URL piece:

var currentURL = window.location.href;

And for the title, document.title:

var title = document.title;
like image 103
Nick Craver Avatar answered Sep 28 '22 09:09

Nick Craver


window.location.href for the URL and document.title for the title.

like image 37
Vivin Paliath Avatar answered Sep 28 '22 10:09

Vivin Paliath