JavaScript将电流域名添加到URL参数



如何使用JavaScript重新定向,然后将其添加到URL参数之前,然后将其添加到此之前:

http://redirecturl.com?domain= {domain}

在下面快速简便的答案。但是,如果没有 stackoverflow

let url = `http://redirecturl.com?domain=${document.location.hostname}`;
console.log( url );

您可以使用简单的location.hostname

const redirectURL = `http://redirecturl.com?domain=${location.hostname}`;
console.log(redirectURL);

es5:

var redirectURL = "http://redirecturl.com?domain=" + location.hostname;
console.log(redirectURL);


注意:上面的返回stacksnippets.net,因为这是Stackoverflow运行片段的地方(您将查看是否访问网站

最新更新