2015-01-09 64 views

回答

0
var loc=window.location.href; 
var path=loc.substring(19);//flesh this out to be smarter for your use case 
var newdomain = "sub2.maindomain.com"; 

var link=jQuery("#linkid").attr('href',newdomain+path); 
+1

请向OP(以及未来的访问者)解释为什么你做了你所做的事情。 – 2015-01-09 21:27:58

0

您可以使用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. 
相关问题