您的位置:首页 > Web前端 > JavaScript

JS 打开一个模式窗口,使用Cookie传递一个参数

2014-11-13 16:01 666 查看
页面A,加载后打开一个模式窗口,设置一个参数,然后自己关闭

<html>
<head>
<script language="javascript">
function fullScreen(){
loadpopup();
var width = screen.width-10;
var height = screen.height-60;
window.open("b.html","","left=0,top=0,width="+width+",height="+height+",title=yes,scrollbars=yes,resizable=no,location=no,toolbar=no, menubar=no");
closeit();
}
//设置时间自动关闭本页面
function closeit(){
setTimeout("self.close()",3000) //毫秒
}
function loadpopup(){
if (get_cookie('popped')==''){
document.cookie="popped=yes";
}
}
//通过名称得到Cookie的内容
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
</script>
</head>
<body onload="fullScreen()">
</body>
</html>

 页面B, 取得参数内容并弹出

<html>
<head>
<script language="javascript">
function winload(){
alert(get_cookie('popped'));
}
//通过名称得到Cookie的内容
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
</script>
</head>
<body onload="winload()">
</body>
</html>

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: