最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

get URL, get Title by Javascript not jQuery - Stack Overflow

programmeradmin4浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 8

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;

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

var title = document.getElementsByTagName('title')[0].innerHTML;
var url = document.location.href;
发布评论

评论列表(0)

  1. 暂无评论