请大家多帮忙,我刚学习js,怎么也弄不明白下面的代码,可以的话请帮忙标上注解,多谢。
<script type="text/javascript">function $(id){return document.getElementById(id);}
function rdckie(name)
{
var re='',mycc=document.cookie;
var ex=new RegExp(name+"=([^;]*)");
if(ex.test(mycc))
{re=unescape(RegExp.$1);}
return re;
}
function fbody(){document.write('<body onclick="nextok()">');}
function ob_hid(id,flag){if($(id)) $(id).style.display=(flag)?'none':'block';}
function nextok()
{
//return;
var aa=location.hostname.split('.'),preu=document.referrer;
var bz=document.compatMode=="CSS1Compat"?document.documentElement:document.body;
if(!document.all || rdckie('fid') || rdckie('hi_auth') || !preu){toseh();return;}//  || preu.match(/\.soso\.com/i)
if(!$('ndiv'))
{
var bd=document.getElementsByTagName("body").item(0);
var obnew=document.createElement('div');
obnew.setAttribute('id','ndiv');
obnew.className='test';
bd.appendChild(obnew);
var ht1=bz.scrollHeight,ht2=bz.clientHeight;
obnew.style.height=((ht1>ht2)?ht1:ht2)+"px";
if(!$('mdiv'))
{
var obnew=document.createElement('iframe');
obnew.setAttribute('id','mdiv');
obnew.className='test1';
bd.appendChild(obnew);
}
}
ob_hid('ndiv');ob_hid('mdiv');
$('mdiv').style.top=bz.scrollTop+(bz.clientHeight-$('mdiv').offsetHeight)/2+'px';
$('mdiv').style.left=((bz.clientWidth-$('mdiv').offsetWidth)/2+15)+'px';
}
function toseh()
{
ob_hid('ndiv',1);ob_hid('mdiv',1);
if(rdckie('fid')) return;
var n=new Date();
n.setTime(n.getTime()+360000);
document.cookie="fid=1;path=/;expires="+n.toGMTString();
}</script>
这段代码究竟是干什么用的啊,我自己弄了n遍也运行不了啊,是不是cookie的原因啊?

解决方案 »

  1.   


    function $(id){return document.getElementById(id);} //一个函数,函数名为$
    function rdckie(name) //这个函数是用来读cookie的
    {
    var re='',mycc=document.cookie;
    var ex=new RegExp(name+"=([^;]*)");
    if(ex.test(mycc))
    {re=unescape(RegExp.$1);}
    return re;
    }
    function fbody(){document.write('<body onclick="nextok()">');} //这个函数是用来写body前标签的
    function ob_hid(id,flag){if($(id)) $(id).style.display=(flag)?'none':'block';} //这个传递2个参数,id是元素的ID,flag是标识,用来显隐元素的
    function nextok() //这个就是你的fbody里面点击整个页面文档部分都会触发的函数.
    {
    //return;
    var aa=location.hostname.split('.'),preu=document.referrer;
    var bz=document.compatMode=="CSS1Compat"?document.documentElement:document.body;
    if(!document.all || rdckie('fid') || rdckie('hi_auth') || !preu){toseh();return;}// || preu.match(/\.soso\.com/i)
    if(!$('ndiv'))
    {
    var bd=document.getElementsByTagName("body").item(0);
    var obnew=document.createElement('div');
    obnew.setAttribute('id','ndiv');
    obnew.className='test';
    bd.appendChild(obnew);
    var ht1=bz.scrollHeight,ht2=bz.clientHeight;
    obnew.style.height=((ht1>ht2)?ht1:ht2)+"px";
    if(!$('mdiv'))
    {
    var obnew=document.createElement('iframe');
    obnew.setAttribute('id','mdiv');
    obnew.className='test1';
    bd.appendChild(obnew);
    }
    }
    ob_hid('ndiv');ob_hid('mdiv');
    $('mdiv').style.top=bz.scrollTop+(bz.clientHeight-$('mdiv').offsetHeight)/2+'px';
    $('mdiv').style.left=((bz.clientWidth-$('mdiv').offsetWidth)/2+15)+'px';
    }
    function toseh() //隐藏ndiv和mdiv,如果fid这个cookie存在,则退出,不存在则写入这个cookie
    {
    ob_hid('ndiv',1);ob_hid('mdiv',1);
    if(rdckie('fid')) return;
    var n=new Date();
    n.setTime(n.getTime()+360000);
    document.cookie="fid=1;path=/;expires="+n.toGMTString();
    }