我得到太多的方法可以得到像下面的代码的主机的主机名(基本URL):得到使用JavaScript
window.location.host // you'll get sub.domain.com:8080 or sub.domain.com:80
window.location.hostname // you'll get sub.domain.com
window.location.protocol // you'll get http:
window.location.port // you'll get 8080 or 80
window.location.pathname // you'll get /virtualPath
在我来说,我想要的东西不同。例如:
我的QA网站的名称是example.com/testsite/index.html
我PROD网站的名称是example.com/index.html
这里的问题使用上述方法来获得它返回我只喜欢这个主机的主机名:example.com
然而,对于QA我需要返回example.com/testsite
对于PROD我需要返回example.com
单个代码可能吗?提前致谢。
最好的方法,你已经拥有的INF ormation你需要...'window.location.hostname + window.location.pathname'我不明白是什么问题:/ – vsync
感谢您的评论, 但我不知道我是否在质量保证或产品代码侧。来制作实际的路径 –
你的问题的标题并不代表你正面临的问题 – vsync