leben
V2EX  ›  问与答

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

  •  
  •   leben · Jul 10, 2012 · 5053 views
    This topic created in 5251 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
    manhere
    Jul 10, 2012
    1
    folders前面加一个/试试?
    zythum
    zythum
    Jul 10, 2012
    2
    不行 ./folders 试试
    leben
    leben
    OP
    Jul 10, 2012
    3
    @manhere @zythum 谢谢。
    leben
    leben
    OP
    Jul 10, 2012
    4
    @manhere 加/直接退到host上了。连虚拟目录都不考虑了。
    @zythum ./在ie和ff上介绍还是不一样。

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