我在 Firefox 中将此用作书签,但是当我访问该页面并尝试加载书签时,它什么也没做。我的 JS 代码有问题吗?
在用户 KURT 的建议下,我能够通过以下方式解决这个问题:
javascript: (function () {
function getCookie(name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf( 'JSESSIONID' + '=');
if (c_start != -1) {
c_start = c_start + 'JSESSIONID'.length + 1;
c_end = document.cookie.indexOf(';', c_start);
if (c_end == -1) c_end = document.cookie.length;
return unescape(document.cookie.substring(c_start, c_end))
}
}
return null;
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
var thedc = readCookie("dc");
if (thedc.substring(0, 2) == 'SP') {
alert(' in SP ');
} else {
alert(' in WC ');
}
}());