求一JS网址自动转向代码

gkyu98 2011-07-14 04:56:13
这样子可以实现
var geturl=location.href;
if(geturl=='http://baidu.com/'||geturl=='http://baidu.com'||geturl=='baidu.com') {
location.href='http://www.baidu.com/'
}


现在需要内页也实现这样的自动转向,如何处理?
比如:baidu.com/product/25.html
能自动转成http://www.baidu.com/product/25.html
...全文
78 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsw645645645 2011-07-15
  • 打赏
  • 举报
回复

var geturl=location.href;
location.href=geturl.replace('baidu.com/','http://www.baidu.com/');

lsw645645645 2011-07-15
  • 打赏
  • 举报
回复
var geturl=location.href;
if(geturl=='http://baidu.com/'||geturl=='http://baidu.com'||geturl=='baidu.com') {
location.href=geturl.replace('baidu.com/','http://www.baidu.com/');
}
xuexiaodong2009 2011-07-14
  • 打赏
  • 举报
回复
正则表达式匹配转化
itliyi 2011-07-14
  • 打赏
  • 举报
回复
http://www.baidu.com/product/25.html
不可以?

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧