有谁知道如何在javascript中将window.open(url)分配到cookies数组中?
以下是我目前使用的代码,但似乎对我来说效果不佳....
var expiredays = 30
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie="childWindowHandles["+num+"] =" +window.open(url)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
答案 0 :(得分:0)
document.cookie === String
window.open === Object
对象!==字符串
因此
document.cookie!== window.open
答案 1 :(得分:0)
最好将uri字符串分配到要打开的窗口的cookie数组中,然后在要调用window.open时将其从cookie中拉出。将代码或敏感数据插入cookie并不是一种好的做法或安全。
取自http://www.quirksmode.org/js/cookies.html
的职能function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
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;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
然后你可以去:
createCookie('openUri', uriToOpen);
var openUri = readCookie('openUri');
if (openUri) {
window.open(openUri, 'myWindow');
}
或类似的东西。
希望这有帮助。