我有一个域名:TestSite.com.我为这个网站创建了几个子域名,并将它们作为first.TestSite.com,second.TestSite.com等引用.
如何在第一个.TestSite.com的html或aspx文件中,不用硬编码代码,相对于TestSite.com?我的意思是(使用文件夹作为示例),如果我有一个文件夹TestSite和一个子文件夹
TestSite/first
../
从First.TestSite.com来看,我该用什么来引用TestSite.com?谢谢.
解决方法
没有办法使用纯粹的相对链接.您必须将其编程为字符串操作.
就像是:
var host = location.host; var lastPeriod = host.lastIndexOf("."); var remainder = host.substring(0,lastPeriod); var afterSecondLastPeriod = remainder.lastIndexOf('.') + 1 var baseDomain = host.substring(afterSecondLastPeriod); console.log(baseDomain);
编辑:使用正则表达式的较短版本:
var baseDomain = host.match(/[^.]*\.[^.]*$/)[0]
这是一般的,所以它总是返回最后一部分.无论是a.TestSite.com,b.a.TestSite.com等,都将返回TestSite.com.
如果这个假设不正确,你将不得不修改它.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。