Connecting Tech Pros Worldwide Help | Site Map

Url encoding problem

Member
 
Join Date: Nov 2007
Posts: 56
#1: 3 Weeks Ago
Hello everyone,

I'm having a problem here.

I'm using a HTML application to generate reports as htm-files.
Now I want to add a print function to make it all a bit easier.

So I came up with this:
Expand|Select|Wrap|Line Numbers
  1. function printfile(filetoprint)
  2. {
  3. var popup = window.open(filetoprint);
  4. popup.focus(); 
  5. popup.print(); 
  6. popup.close();
  7. }
  8.  
You'll probably say: "Nothing wrong with that code." :-) Thank you, it is working fine
.
The problem lies however in my filename. When I wrote the code I added a # to the filename. The problem is now that when I try to open the file the browser tries to execute it, because he sees it as an anchor.

A small example of a filename: "F09-084 # status ().htm"
When I try to open it, the browser is looking for the file called F09-084 and nothing more.

I tried escaping the # and I tried encoding it %23 but no luck.

Does anyone have an idea how to open a file without having the browser look for the anchorpoint?

Regards,

Kenneth
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: 3 Weeks Ago

re: Url encoding problem


Two things you can try:
1. Avoid # - simple, but may still cause problems.
2. Encode the URI:
Expand|Select|Wrap|Line Numbers
  1. encodeURI(filetoprint)
Member
 
Join Date: Nov 2007
Posts: 56
#3: 2 Weeks Ago

re: Url encoding problem


Thanks for the reply acoder but it doesn't seem to work.
I looked further on the net and I even found the encodeURIComponent() which appearantly has to be used for characters like # but that didn't work as well.

So in the end I adapted all the filenames to replace the # by a §. And that doesn't provide any problems.

Greets,

Cainnech
Reply