document.referrer result being truncated!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gocre8
    New Member
    • Oct 2006
    • 1

    document.referrer result being truncated!

    hope someone can advise! . . .

    i'm using this code...

    Code:
    <SCRIPT LANGUAGE="JavaScript">
     document.write("<INPUT type=hidden NAME=referrer VALUE=" + 'document.referrer' + ">");
    </SCRIPT>
    to generate a hidden field to be submitted with a php formmail script, so i know from which url the visitor has filled in the form. this works well, except for the fact that the url is truncated/corrupted in some way at the end so this....

    gallery/index.php?level =picture&id=256

    ends up like this...

    gallery/index.php?level =picture&id%6

    this is obviously a pain in the arse as the info is of no use unless its the the full, unabridged url!

    any advice appreciated!

    many thanks :)
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use encodeURI() or encodeURICompon ent() and decodeURICompon ent() to encode/decode the URL.
    Code:
    <script type="text/javascript">
     document.write("<input type='hidden' name='referrer' value='" + encodeURI(document.referrer) + "'>");
    </script>

    Comment

    Working...