Don*_*ias 6 javascript cookies internet-explorer asp-classic
我有一些代码将用户的ID保存为cookie.它在生产中运行良好,但将代码移动到IIS7,在我的代码后面升级供应商应用程序,并将应用程序移动到IIS7中的应用程序而不是仅运行默认Web在IE中打破此cookie功能.
不幸的是,它是一个经典的ASP应用程序,所以我找不到一个发布工作版本的好方法.但这里有相关的部分.
概要:
似乎正在发生的事情(仅在IE?)是有2个cookie,取消选中该框仅触及其中一个.
这是相关的代码.希望能帮助到你 :)
在登录表单上:
var MHOLI = Get_Cookie("MHOLI");
//Check if cookie has a value
if (MHOLI != null && MHOLI != "" && MHOLI != "null") {
//Set login text
$("#Login").val(MHOLI);
//keep remember login checkbox checked
$("#RemonlineID").attr('checked', true);
$(document).ready(function() {
setTimeout(function() {
$("#Password").focus();
}, 200);
});
}
$(document).ready(function() {
//test if cookies are enabled..
Set_Cookie('test', 'testvalue', '/', '', '');
//if cookies are disabled, disable the option to remember username
if (!Get_Cookie('test')) {
$('#RemonlineID').attr("disabled", true);
}
});?
Run Code Online (Sandbox Code Playgroud)
当"记住我"复选框被更改时:
var loginForm = document.getElementById("loginForm");
if (!loginForm.RemonlineID.checked) {
setCookie("MHOLI", null, null);
setCookie("tmpMHOLI", null, null);
}?
Run Code Online (Sandbox Code Playgroud)
提交登录表单后,如果选中"记住我",请设置1天的cookie:
if (loginForm.RemonlineID.checked) {
setCookie("tmpMHOLI", loginForm.Login.value, 1);
}
else {
setCookie("tmpMHOLI", null, null);
}?
Run Code Online (Sandbox Code Playgroud)
setCookie函数.是的,我看到expstring那里但从未使用过:):
function setCookie(name, value, days) {
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring = (typeof days != "undefined") ? expireDate.setDate(expireDate.getDate() + parseInt(days)) : expireDate.setDate(expireDate.getDate() - 5)
document.cookie = name + "=" + value + "; expires=" + expireDate.toGMTString();
}?
Run Code Online (Sandbox Code Playgroud)
一旦用户进入应用程序,就会有一些VBScript.我在想它正在创建第二个cookie而不是
if Request.Cookies("tmpMHOLI") <> "" then
Response.Cookies("MHOLI") = Request.Cookies("tmpMHOLI")
Response.Cookies("MHOLI").Expires = Date() + 365
Response.Cookies("tmpMHOLI") = ""
end if?
Run Code Online (Sandbox Code Playgroud)
关于IE7/8/9处理cookie的方法有什么不同吗?有没有关于IIS7.5创建一个客户端脚本无法触及的cookie?
我最终重构了我的setCookie()功能。我没有正确地让cookie过期,因为日期计算很奇怪。quirksmodecreateCookie()功能工作正常。
另外,我在服务器端设置 cookie 时设置了路径。不知何故,登录前和登录后页面设置的 cookie 路径不同。因此客户端脚本无法覆盖服务器端 cookie,反之亦然。显式设置路径解决了这个问题。
| 归档时间: |
|
| 查看次数: |
1312 次 |
| 最近记录: |