V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
jacy
V2EX  ›  JavaScript

js菜鸟,求写一小段代码

  •  
  •   jacy · 2012-11-20 00:11:43 +08:00 · 3015 次点击
    这是一个创建于 4147 天前的主题,其中的信息可能已经有所发展或是发生改变。
    写一个html文件,用javascript判断当前域名,如果是www.baidu.com,就跳转到www.baidu.com:88,否则不做处理
    比如网址是http://www.baidu.com/s?bs=lv&f=8&rsv_bp=1&rsv_spt=3&wd=123,那么跳转到http://www.baidu.com:88/s?bs=lv&f=8&rsv_bp=1&rsv_spt=3&wd=123
    8 条回复    1970-01-01 08:00:00 +08:00
    zyAndroid
        1
    zyAndroid  
       2012-11-20 00:17:11 +08:00
    location.host
    bitsmix
        2
    bitsmix  
       2012-11-20 00:18:08 +08:00
    window.location.hostname === 'v2ex.com' ? (window.location.href = 'http://' + window.location.hostname + ':88' + window.location.pathname): console.log('oops')
    SAGAN
        3
    SAGAN  
       2012-11-20 00:18:45 +08:00
    if( location.hostname == "www.baidu.com" )
    location="http://www.baidu.com:88/";
    NemoAlex
        4
    NemoAlex  
       2012-11-20 00:19:10 +08:00
    if (location.host == 'www.baidu.com') location.href = location.href.replace('//www.baidu.com/', '//www.baidu.com:88/');
    Julyyq
        5
    Julyyq  
       2012-11-20 00:29:48 +08:00   ❤️ 1
    var oHost=location.host;
    var setUrl="";
    if(oHost.indexOf("baidu") !=-1) {
    var oUrl=location.href.replace(/baidu.com/,"baidu.com:88")
    setUrl=oUrl;
    }
    拿去吧,不用谢。
    bitsmix
        6
    bitsmix  
       2012-11-20 00:42:55 +08:00
    @NemoAlex 你把 replace 理解错了
    jacy
        7
    jacy  
    OP
       2012-11-20 00:44:55 +08:00
    谢谢上面几位。准备在路由器上劫持百度,可是80端口的http服务器不支持php,我准备用php做点文章。
    NemoAlex
        8
    NemoAlex  
       2012-11-20 01:27:13 +08:00
    @bitsmix 嗯?怎么说?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1430 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:48 · PVG 07:48 · LAX 16:48 · JFK 19:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.