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

2019-09-14 03:58发布

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条回答
乱世女痞
2楼-- · 2019-09-14 04:58

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.

查看更多
登录 后发表回答