Url encoding problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cainnech
    New Member
    • Nov 2007
    • 132

    Url encoding problem

    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:
    Code:
    function printfile(filetoprint)
    {
    var popup = window.open(filetoprint);
    popup.focus(); 
    popup.print(); 
    popup.close();
    }
    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
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Two things you can try:
    1. Avoid # - simple, but may still cause problems.
    2. Encode the URI:
    Code:
    encodeURI(filetoprint)

    Comment

    • Cainnech
      New Member
      • Nov 2007
      • 132

      #3
      Thanks for the reply acoder but it doesn't seem to work.
      I looked further on the net and I even found the encodeURICompon ent() 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

      Comment

      Working...