通过js获取当前根网址

  当前根网址是指当前完整网址中去掉域名后面斜杆之后部分的网址,例如http://blog.qianmu.net/?home&action=add的根网址是http://blog.qianmu.wang/。

  在使用千木万能建站程序时可能会需要用js获取当前根网址,方法如下:

<script>
  var cthost = getcthost();
  functiono getcthost(){
    var protocol = windows.location.protocol;//http:
    var host= windows.location.host;//blog.qianmu.net
    var cthost = protocol + '//' + host + '/';//http://blog.qianmu.net/
  }
</script>
标签:js
分类:编程笔记 时间:2021年03月19日 浏览:187