leben
V2EX  ›  问与答

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

  •  
  •   leben · Jul 10, 2012 · 4565 views
    This topic created in 5060 days ago, the information mentioned may be changed or developed.
    在localhost/site/files这个页面上,使用window.location.href='folders'跳转。
    在firefox下可一正常跳转到localhost/site/folders
    但是在IE下跳转到了localhost/stie/files/folders

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

    感觉问题是出在refer上。ie是以当前current url,ff和chrome都是用的根目录(包括host和虚拟目录,可能和我在head里设置的base有关系。)
    caoyue
        5
    caoyue  
       Jul 10, 2012
    为什么不直接写 “/site/folders” 呢……
    leben
        6
    leben  
    OP
       Jul 10, 2012
    @caoyue /site是虚拟目录、alias。呵呵,我都不知道这个现在应该怎么叫了。
    我定义了绝对路径,搜了一下,都说在javascript跳转的时候最好使用绝对路径。
    谢谢了。
    NemoAlex
        7
    NemoAlex  
       Jul 10, 2012
    如果写 ../folders 会怎样
    flyingnn
        8
    flyingnn  
       Jul 10, 2012
    location.protocol + "//" + location.host + location.pathname
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1111 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 18:17 · PVG 02:17 · LAX 11:17 · JFK 14:17
    ♥ Do have faith in what you're doing.