What is the difference in “/urlString.html” versus “urlString.html” in window.location?

徘徊边缘 提交于 2019-12-11 19:02:08

问题


I recently ran into an issue when preparing a web app to work in IE11. I've found a working solution but I would prefer to have a good reason why it worked rather than a guess.

My issue was an incorrect path when redirecting from the URL (http: //localhost:4724/View/Completion) to an exit page using the following javascript:

window.location = "Exit.aspx?timeout=true";

This resulted in a URL like so in IE11. Note the extra /View/:

http: //localhost:4724/View/Exit.aspx?timeout=true

In Chrome it results in the correct URL of:

http: //localhost:4724/Exit.aspx?timeout=true

I was able to correct the issue by including a forward slash when using window.location like so:

window.location = "/Exit.aspx?timeout=true";

Then it correctly routes Chrome and IE11 to the URL of:

http ://localhost:4724/Exit.aspx?timeout=true

What is IE11 interpreting differently when I include the forward slash for the window.location string?


回答1:


A leading slash indicates an absolute path, i.e. a path relative to the root of the website. Without the leading slash the path is relative to the current URL.

Why it behaves differently in different browsers I can not say.



来源:https://stackoverflow.com/questions/22666166/what-is-the-difference-in-urlstring-html-versus-urlstring-html-in-window-lo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!