10

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.

unor
  • 92,415
  • 26
  • 211
  • 360
ajimenez
  • 175
  • 2
  • 14
  • 2
    Using `aaaa_%23_aaaa.msg` worked for me on IE8. – Hashem Qolami Feb 03 '14 at 12:37
  • 1
    Just tested: `%23` works in Firefox/26, Chrome/32, Opera/12.16 and Explorer/11 (all running on Windows 7). What target browser is it failing for? – Álvaro González Feb 03 '14 at 12:41
  • 3
    If I put this "aaaa_%23_aaaa.msg" direct into the adress bar is working, but when I put an anchor like `aaaa_#_aaa.msg` In IE11 is trying to open `file://attachments/aaaa_%2523_aaa.msg` – ajimenez Feb 03 '14 at 12:49
  • I still cannot reproduce, though I admit I had to rewrite the URL prefix to make it absolute (`file:///C:/attachments/`); otherwise, it didn't work in any browser no matter the file name. – Álvaro González Feb 03 '14 at 15:45
  • @user2244596 your problem is that "%" is being url encoded so it is encoded to "%25" and 23 is then handled as usual chars. Are you using some encoding function? BTW My IE11 works even through your anchor tag example :) – jave.web Feb 06 '14 at 21:13
  • Not, I'm not using any encoded function, just put the the anchor tag in my asp file with the url retrieve from db. And only IE11 is making this encode for '%'. Finally I can't solved the problem directly, but I've could change the source process to change special characters in the files. – ajimenez Feb 07 '14 at 09:24
  • have you tried putting single quotes instead of double quotes. I know some languages make a difference by interpreting doubles quotes but letting as is single quotes. Don't know if that tricks works on pure html though. – Miraino Hikari Feb 07 '14 at 15:22

1 Answers1

2

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.

Steve Schneider
  • 392
  • 2
  • 5
  • Do you have any reference on that? As far as I know, `#` is a plain US-ASCII character that doesn't have any special meaning in any Unix file system I'm aware of. And encoding it in a URL is straightforward (unlike other Unicode characters that have different encodings in Latin1 and UTF-8). – Álvaro González Feb 10 '14 at 08:53
  • @Álvaro G. Vicario, I don't have a reference; I have a memory of being on some UNIX flavor and not being able to use "#". And given it has a special meaning in URLs as well as being a comment identifier in some programming languages, I avoid it and it's worked well for me. E.g., I haven't run into any issues such as the OP has :) – Steve Schneider Feb 13 '14 at 20:03
  • I just made a file named "PO# tralala.pdf" in Fedora 23 with an ext4 filesystem. So yeah. – Ray Foss Apr 15 '16 at 13:18