【发布时间】:2014-05-02 10:25:52
【问题描述】:
我有网站: "http://www.example.com/folder1/mywebsite/subfolder/page.html"
网站的根是:“http://www.example.com/folder1/mywebsite”
我想动态获取“mywebsite”的根网址。 如果我将此站点发布到其他地方,则无需更改脚本。
例如:“http://www.example.com/otherFolder/test/myChangedWebsite/subfolder/page.html”
我会得到: "http://www.example.com/otherFolder/test/myChangedWebsite"
我在“page.html”javascript中试过: var url = window.location.protocol + "//" + window.location.host + '/otherPage.html
但这只给了我“http://www.example.com/otherPage.html”。
我也知道 location.origin,但并非所有浏览器都支持,因为我在链接上发现:http://www.w3schools.com/jsref/prop_loc_origin.asp
如果可以用 jQuery 来做,那就太好了。
【问题讨论】:
标签: javascript jquery html