文档.引荐来源网址编码问题
document.referrer encoding issue
referrer' 并将值保存在 cookie 中。结果是这样的,带有奇怪的字符:
http%3A//www.rzammit.com/props/testpage.asp%3Fadv%3D123%26loc%3D45
我如何删除那些奇怪的字符,以便链接正确显示?
谢谢
- 使用在返回 Cookie 之前取消转义 Cookie 的 Cookie 脚本,或者
- 看看这里如何urldecode:Javascript相当于php的urldecode()
var url = "http%3A//www.rzammit.com/props/testpage.asp%3Fadv%3D123%26loc%3D45";
url = decodeURIComponent(url.replace(/'+/g, ' '));
这是我自 90 年代中期以来使用的 cookiescript - 免费用 encodeURIComponent 替换 escape 和用解码 URIComponent 替换 unescape 以将其带入 2010 年代;)
// 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";
}
相关文章:
- ajax表单提交的编码问题
- 导出为 CSV 时的编码问题
- 地理编码器 - IE8 中的编码问题
- 参数未正确传递给AJAX-编码问题
- AngularJS/Grunt编码问题
- Outlook中的HTML锚定邮件主题编码问题
- NetSuite Restlet PDF 文件编码问题
- 在安卓中使用 JavaScript 设置内容时出现编码问题
- Javascript到csv导出编码问题
- 为什么此字符编码问题仅在选定系统上出现
- JavaScript utf-8 编码问题
- JavaScript WebSocket 字符编码问题(文本)
- 文档.引荐来源网址编码问题
- jquery单词计数器的输入编码问题
- JSP、JQuery和Javascript的字符集编码问题
- 外部gem的资产管道编码问题(UTF-8与ASCII-8BIT)
- 集成Moment JS库时出现编码问题
- Expressjs:res.download期间图像文件编码问题
- php中日语字符的编码问题
- Strophe字符编码问题