我想写一个javascript,实现如下的页面转向,可我不会写,请大家帮帮忙原来url: http://abc.com/article/archives/<number>
跳转到:http://xyz.com/archives/<number>原来url还有可能是: http://abc.com/article/<letters>
跳转到:http://xyz.com/<letters><>中的内容是可变的,也就是参数,请帮帮忙吧。我必须今天晚上有结果啊。
各位大哥大姐叔叔阿姨帮帮忙!
跳转到:http://xyz.com/archives/<number>原来url还有可能是: http://abc.com/article/<letters>
跳转到:http://xyz.com/<letters><>中的内容是可变的,也就是参数,请帮帮忙吧。我必须今天晚上有结果啊。
各位大哥大姐叔叔阿姨帮帮忙!
var stemp = 'http://abc.com/article/archives/';
var s1 = 'http://abc.com/article/archives/344';
if (s1.indexOf(stemp)==0) {
var number = parseInt(s1.substring(stemp.length));
var s2 = 'http://xyz.com/archives/' + number;
window.location = s2;
}
function reloc(url) {
var stemp1 = 'http://abc.com/article/archives/';
var stemp2 = 'http://abc.com/article/';
if (url.indexOf(stemp1)==0) {
var number = url.substring(stemp1.length);
window.location = 'http://xyz.com/archives/' + number;
}
else if (url.indexOf(stemp2)==0) {
var letter = url.substring(stemp2.length);
window.location = 'http://xyz.com/' + letter;
}
}
http://abc.com/article/<letters>http://xyz.com/archives/<number>
http://xyz.com/<letters>看你的介绍,根本就用不着提取,只需要简单的替换就可以了
var uri1="http://abc.com/article/archives/number";
var uri2="http://abc.com/article/letters";
uri1=uri1.replace("http://abc.com/article","http://xyz.com");
uri2=uri2.replace("http://abc.com/article","http://xyz.com");也就是将http://abc.com/article替换成http://xyz.com
function onload() {
location.href = location.href.replace('http://abc.com/article/', http://xyz.com/);
}
</script>
function onload() {
location.href = location.href.replace('http://abc.com/article/', 'http://xyz.com/');
}
</script>