![](/img/trans.png)
[英]TinyBox2: how to make ajax url relative to base domain url not to current page
[英]Is the current page the base url?
我需要查看用户当前页面是否是网站的主页面,即基本网址后面没有任何内容。
我这样做是为了从主页面中排除一些代码。
if (location.pathname=="/"){
// at the root of the site
}
阅读(跨浏览器) window.location
对象的更多信息。
编辑 :如果您的“root”可能由名为index
文件(例如index.html
, index.php
, index.asp
等)提供,您可能需要:
var rootPattern = /^\/(?:index\.[^.\/]+)?$/i;
if (rootPattern.test( location.pathname )){
// …
}
或更明确地:
switch(location.pathname){
case '/':
case '/index.html':
case '/index.php':
case '/index.asp':
// …
}
if (location.pathname == "/" || location.pathname == "/index.html" || location.pathname == "/index.php"){
// at the "main page" of the site
}
更多信息: http : //www.w3schools.com/jsref/prop_loc_pathname.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.