V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
leben
V2EX  ›  问与答

请教关于IE/Firefox下location.href跳转的问题。

  •  
  •   leben · 2012-07-10 17:28:57 +08:00 · 3676 次点击
    这是一个创建于 4279 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在localhost/site/files这个页面上,使用window.location.href='folders'跳转。
    在firefox下可一正常跳转到localhost/site/folders
    但是在IE下跳转到了localhost/stie/files/folders

    囧死了,难道必须要写完整的路径才能正常跳转?
    求大神指教,谢谢。
    8 条回复    1970-01-01 08:00:00 +08:00
    manhere
        1
    manhere  
       2012-07-10 17:31:41 +08:00
    folders前面加一个/试试?
    zythum
        2
    zythum  
       2012-07-10 17:34:16 +08:00
    不行 ./folders 试试
    leben
        3
    leben  
    OP
       2012-07-10 17:50:35 +08:00
    @manhere @zythum 谢谢。
    leben
        4
    leben  
    OP
       2012-07-10 17:59:49 +08:00
    @manhere 加/直接退到host上了。连虚拟目录都不考虑了。
    @zythum ./在ie和ff上介绍还是不一样。

    感觉问题是出在refer上。ie是以当前current url,ff和chrome都是用的根目录(包括host和虚拟目录,可能和我在head里设置的base有关系。)
    caoyue
        5
    caoyue  
       2012-07-10 18:04:18 +08:00
    为什么不直接写 “/site/folders” 呢……
    leben
        6
    leben  
    OP
       2012-07-10 18:32:03 +08:00
    @caoyue /site是虚拟目录、alias。呵呵,我都不知道这个现在应该怎么叫了。
    我定义了绝对路径,搜了一下,都说在javascript跳转的时候最好使用绝对路径。
    谢谢了。
    NemoAlex
        7
    NemoAlex  
       2012-07-10 19:16:45 +08:00
    如果写 ../folders 会怎样
    flyingnn
        8
    flyingnn  
       2012-07-10 22:59:15 +08:00
    location.protocol + "//" + location.host + location.pathname
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5552 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 06:37 · PVG 14:37 · LAX 23:37 · JFK 02:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.