gpt4 book ai didi

javascript - 使用Javascript将页面从子域链接到具有相同结构子文件夹的另一个子域

转载 作者:行者123 更新时间:2023-11-28 07:42:19 25 4
gpt4 key购买 nike

我正在尝试创建一个按钮来链接子域,但保持页面的相同路径。

点击它来自

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com