Javascript 如何使用单一代码更改网站的域URL和网站的子链接?
我想添加一个字符串到主域,也到网站的子链接 我尝试了下面的代码,但主域没有得到改变,我想改变主域的网站后,所有的子链接应该改变第一次重新加载Javascript 如何使用单一代码更改网站的域URL和网站的子链接?,javascript,jquery,Javascript,Jquery,我想添加一个字符串到主域,也到网站的子链接 我尝试了下面的代码,但主域没有得到改变,我想改变主域的网站后,所有的子链接应该改变第一次重新加载 if (typeof this.href != "undefined") { web = this.href.toString().toLowerCase(); } else{ web = document.location.toString().toLowerCase(); } func
if (typeof this.href != "undefined") {
web = this.href.toString().toLowerCase();
}
else{
web = document.location.toString().toLowerCase();
}
function urlAddress() {
confirm('Would you like to clear the cache.......... of '+ web + '- Ninja :)');
//window.location.replace(web + "/?NoCDN=123");
var stateObj = web;
if (window.history.state) {
history.pushState(stateObj, "page 1", "/?NoCDN=123");
}
}
/*Second Function
This code is changing all URL of the website...*/
function linkAddress() {
$('a[href]').each(function(){
var link = this.href;
$(this).attr('href',link + '?NoCDN=123');
});
$('script[src]').each(function(){
var link = this.href;
$(this).attr('src',link + '?NoCDN=123');
});
$('link[href]').each(function(){
var link = this.href;
$(this).attr('href',link + '?NoCDN=123');
});
$('img[src]').each(function(){
var link = this.src;
$(this).attr('src',link + '?NoCDN=123');
});
}
//I am calling both functions here ...
$( document ).ready(function() {
urlAddress();
setTimeout(function(){
alert("It's Almost clear. Just click Ok for more result.");
linkAddress();
}, 3000);
});