Use character # in URL inside file name

陌路散爱 提交于 2021-02-04 17:28:09

问题


I need to put a link with this href="file://attachments/aaaa_#_aaaa.msg" Obviously in that way is not working because the hash character # is used for anchors.

So I try to change this to: href="file://attachments/aaaa_%23_aaaa.msg" but when I open the url in the IE, the browser is trying to open this: href="file://attachments/aaaa_%2523_aaaa.msg" IE is encoding the % character to %25

How can I put the file name in the URL to encode and read the hash character # in all the browsers to download the file?

I can't change the file name to remove this character, so I need a way to deal with this problem.


回答1:


You will avoid lots and lots and lots of pain if you are able to rename your files so they don't contain a "#" character. As long as they do, you will probably have current and future cross-browser issues, confusion on behalf of future developers working on your code (or confusion on your behalf in the future, when you've forgotten the ins and outs of the encoding), etc. Also, some Unix/Linux systems don't allow "#" in filenames. Not sure what OS you're using, but your filenames should be as portable as possible across OSs, even if you're "sure" right now that you'll never be running on one of those systems.



来源:https://stackoverflow.com/questions/21526313/use-character-in-url-inside-file-name

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