Javascript 文档.引用者编码问题
referer`并将值保存在cookie中。结果是这样,出现了一些奇怪的字符:Javascript 文档.引用者编码问题,javascript,jquery,Javascript,Jquery,referer`并将值保存在cookie中。结果是这样,出现了一些奇怪的字符: http%3A//www.rzammit.com/props/testpage.asp%3Fadv%3D123%26loc%3D45 我如何才能删除这些奇怪的字符,使链接将正确显示请 谢谢 使用cookie脚本,在返回cookie或 请看下面的URL解码方法: 这是我从90年代中期开始使用的cookiescript——免费用encodeURIComponent替换escape,用decodeURIComponen
http%3A//www.rzammit.com/props/testpage.asp%3Fadv%3D123%26loc%3D45
我如何才能删除这些奇怪的字符,使链接将正确显示请
谢谢
这是我从90年代中期开始使用的cookiescript——免费用encodeURIComponent替换escape,用decodeURIComponent替换unescape,将其带入2010年代;)
他直接处理的不是
文档。referer
,而是通过cookie传递的值<代码>文档。引用者不是URL编码的。
var url = "http%3A//www.rzammit.com/props/testpage.asp%3Fadv%3D123%26loc%3D45";
url = decodeURIComponent(url.replace(/\+/g, ' '));
// 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";
}