在文件名内的URL中使用字符# [英] Use character # in URL inside file name

查看:62
本文介绍了在文件名内的URL中使用字符#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要添加与此 href ="file://attachments/aaaa_#_aaaa.msg"的链接显然,这种方式不起作用,因为哈希字符#用于锚点.

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.

所以我尝试将其更改为: href ="file://attachments/aaaa_%23_aaaa.msg" 但是当我在IE中打开url时,浏览器试图打开它: href ="file://attachments/aaaa_%2523_aaaa.msg" IE将字符编码为%25

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

如何在所有浏览器中将文件名放在URL中以进行编码和读取井号#来下载文件?

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.

推荐答案

如果能够重命名文件,使它们不包含#"字符,则将避免很多麻烦.只要他们这样做,您就可能会遇到当前和将来的跨浏览器问题,代表将来开发代码的开发人员会感到困惑(或者,当您忘记编码的来龙去脉时,代表将来的困惑))等.此外,某些Unix/Linux系统不允许在文件名中使用#".不确定您使用的是哪个操作系统,但是即使您现在确定"您永远不会在这些系统之一上运行,您的文件名也应该在各个操作系统之间尽可能地可移植.

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.

这篇关于在文件名内的URL中使用字符#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆