我正在尝试创建一个按钮来链接子域,但保持页面的相同路径。
点击它来自
sub1.maindomain.com/folder01/folder02/folder03/
到
sub2.maindomain.com/folder01/folder02/folder03/
我想编写它的脚本,我希望将其添加到网站模板中。
我的 JS 有点生锈了。
如果您能给我指点,谢谢。
最佳答案
您可以使用location
对象。
var path = location.pathname; //pathname will return the complete path of the uri without the host/domain.
var queryString = location.search.length > 0 ? location.search : ""; //this will retrieve the querystring if available.
var newLink = "sub2.maindomain.com" + path + queryString;
document.getElementById("link").href = newLink; //replace [link] with an id from your anchor element/button element.
关于javascript - 使用Javascript将页面从子域链接到具有相同结构子文件夹的另一个子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27868787/