2012-04-19 16 views
0

referrer`と値をクッキーに保存します。結果は奇妙な文字を次のように来ている:document.referrerエンコーディングの問題

http%3A//www.rzammit.com/props/testpage.asp%3Fadv%3D123%26loc%3D45 

リンクが正しくてください表示されますので、私はこれらの奇妙な文字を削除するにはどうすればよいですか? urldecodeする方法をここで見て、それを返す前に、OR

  • おかげ

  • 答えて

    1
    1. はクッキーをアンエスケープクッキースクリプトを使用:Javascript equivalent to php's urldecode()
    var url = "http%3A//www.rzammit.com/props/testpage.asp%3Fadv%3D123%26loc%3D45"; 
    url = decodeURIComponent(url.replace(/\+/g, ' ')); 
    

    をここにあります90年代半ばから私が使用してきたcookiescript - 手数料encodeURIComponentでそして2010年代にそれを持って来るためには、decodeURIComponentとアンエスケープとエスケープを交換する自由;)

    // cookie.js file 
    var cookieToday = new Date(); 
    var expiryDate = new Date(cookieToday.getTime() + (365 * 86400000)); // a year 
    
    /* Cookie functions originally by Bill Dortsch */ 
    
    function setCookie (name,value,expires,path,theDomain,secure) { 
        value = escape(value); 
        var theCookie = name + "=" + value + 
        ((expires) ? "; expires=" + expires.toGMTString() : "") + 
        ((path)  ? "; path=" + path : "") + 
        ((theDomain) ? "; domain=" + theDomain : "") + 
        ((secure)  ? "; secure"   : ""); 
        document.cookie = theCookie; 
    } 
    
    function getCookie(Name) { 
        var search = Name + "=" 
        if (document.cookie.length > 0) { // if there are any cookies 
         var offset = document.cookie.indexOf(search) 
         if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value 
         var end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value 
         if (end == -1) end = document.cookie.length 
         return unescape(document.cookie.substring(offset, end)) 
         } 
        } 
    } 
    function delCookie(name,path,domain) { 
        if (getCookie(name)) document.cookie = name + "=" + 
         ((path) ? ";path=" + path : "") + 
         ((domain) ? ";domain=" + domain : "") + 
         ";expires=Thu, 01-Jan-70 00:00:01 GMT"; 
    } 
    
    +1

    それは '彼が直接に働いているdocument.referrer'が、クッキーを通した後の値ではありません。 'document.referrer'はURLエンコードされていません。 –

    +0

    ゴティヤ。更新しました。 – mplungjan