【发布时间】:2013-06-25 14:20:17
【问题描述】:
如果 URL 包含单词“hello”,则从 URL 中删除“hello”并重定向。这怎么可能?示例:
在页面加载时,我想检查是否找到“hello”,然后执行:
window.location.href = 'http://www.google.com';
提前致谢
【问题讨论】:
如果 URL 包含单词“hello”,则从 URL 中删除“hello”并重定向。这怎么可能?示例:
在页面加载时,我想检查是否找到“hello”,然后执行:
window.location.href = 'http://www.google.com';
提前致谢
【问题讨论】:
这里不需要jquery:
window.onload = function(){
if(location.href.indexOf('hello') > -1){
location.href = location.href.replace(/hello/,'www');
}
};
【讨论】:
if (url.match(/hello/)) {
window.location.href = url.replace(/hello/, 'www');
}
【讨论】: