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...
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...
Share Improve this question edited Nov 8, 2011 at 21:16 Sampson 268k76 gold badges545 silver badges568 bronze badges asked Dec 6, 2010 at 16:29 Bato DorBato Dor 8413 gold badges11 silver badges33 bronze badges3 Answers
Reset to default 8The 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;
window.location.href
for the URL and document.title
for the title.
var title = document.getElementsByTagName('title')[0].innerHTML;
var url = document.location.href;