how to modify below code?the js code and php code mixed, now i want only js code how to modify below code to change all to js code?(function($){
$(document).ready(function(){ if(empty($_COOKIE["name"])){
var popup = window.open('/main/popup', 'popup', 'top=0,left=0,toolbar=0,directories=0,menubar=0,resizable=0,scrollbars=0,width=300,height=350');
if(popup){popup.focus();}
}
});
})(jQuery);
//////////////////////////////////////////////////////////////////////
<a><img src="/images/pop.jpg"/></a>
<div id="chk" style="position:absolute; top:325px;left:5px">
<input type="checkbox">&nbsp;<b> if click close button, it close one day</b>
<input type="button" value="close" id="closebutton">
</div>
............................................................................................
how to modify below code to change all to js code?
/////////////////////////////////////////////////////////////
<script>
$('a').click(function(){

window.open('/boards/notice/detail/182');
window.close();
});
$("#closebutton").click(function(){
window.close();
var values = 1;
setcookie("name",values,time()+60);

});
</script>

解决方案 »

  1.   

    this is wrong!
    (function($){
    $(document).ready(function(){if(empty($_COOKIE["name"])){
    var popup = window.open('/main/popup', 'popup', 'top=0,left=0,toolbar=0,directories=0,menubar=0,resizable=0,scrollbars=0,width=300,height=350');
    if(popup){popup.focus();}
    }
    });
    })(jQuery);you can use jquery's ajax to require server's message.and then you can use js to write it.
    but you don't write php code in <script> tags
      

  2.   

    na zhe ge zenme xie a ?  you cookie de shihou jiu bu zhixing xia mian dai ma ? na jquery li yinggai zenme panduan you mei you cookie a ?

    var popup = window.open('/main/popup', 'popup', 'top=0,left=0,toolbar=0,directories=0,menubar=0,resizable=0,scrollbars=0,width=300,height=350'); if(popup){popup.focus();}
      

  3.   

    你直接用我开发的这个jquery插件来读取php的cookie吧,不过你必须要知道cookie的名称才行,这个名称和php的不太一样
       //擴展方法,讀寫cookie
        //$.setCookie("a1","abc",999);寫
        //aaa=$.getCookie("a1");讀
        $.extend({getCookie:function(sName){
            var aCookie=document.cookie.split("; ");
            for(var i=0;i<aCookie.length;i++){
                var aCrumb=aCookie[i].split("=");
                if(sName==aCrumb[0]){return decodeURIComponent(aCrumb[1]);}
            }
            return '';
        },setCookie:function(sName,sValue,sExpires){
            var sCookie=sName+"="+encodeURIComponent(sValue);
            if(sExpires!=null){sCookie+="; expires="+sExpires;}
            document.cookie=sCookie;
        },removeCookie:function(sName){
            document.cookie=sName+"=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
        }});
      

  4.   

    我在网站的主页上做了一个弹出窗口,每次登录主页时会弹出这个窗口。但现在想对这个弹出窗口做一个限制。就是在弹出窗口的下面添加一个关闭按钮,当关闭这个按钮的时候,会关闭一天的弹出窗口,第二天登录主页的时候才会弹出这个窗口。php页面代码
    <a><img src="/images/pop.jpg"/></a>
    <div id="chk" style="position:absolute; top:325px;left:5px">
    <input type="checkbox">&nbsp;<b> if click close button, it close one day</b>
    <input type="button" value="close" id="closebutton">
    </div>
    <script>
    $('a').click(function(){
    //opener.location = '/page/view/howto';
    window.open('/boards/notice/detail/182');
    window.close();
    });
    $("#closebutton").click(function(){
    window.close();
    var values = 1;
    setcookie("name",values,time()+60);
    });
    </script>
    index.js页面代码
    (function($){
    $(document).ready(function(){
    if(这里如何获取php页面中设置的cookie){
    var popup = window.open('/main/popup', 'popup', 'top=0,left=0,toolbar=0,directories=0,menubar=0,resizable=0,scrollbars=0,width=300,height=350');
    if(popup){popup.focus();}
    }
    });
    })(jQuery);
    我在php页面里做了,当用户关闭这个弹出窗口的时候生成一个cookie。时间设置一天。
    在调用弹出窗口的index.js页面里用这个cook名称来判断cookie是否存在,如果存在就不执行弹出窗口的代码。等到第二天,cookie消失了,就执行这段弹出窗口的代码,代码在上面,现在问题是index.js页面里如何获取php页面里设置的cookie?
      

  5.   

    代码都给你写好了,你根据自己的要求稍作修改吧.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title> - </title>
    <script type='text/javascript' src="jquery-1.5.2.min.js"></script>
    <script type='text/javascript'>
    (function($){
    //擴展方法,讀寫cookie
    //$.setCookie("a1","abc",999);寫
    //aaa=$.getCookie("a1");讀
    $.extend({getCookie:function(sName){
    var aCookie=document.cookie.split("; ");
    for(var i=0;i<aCookie.length;i++){
    var aCrumb=aCookie[i].split("=");
    if(sName==aCrumb[0]){return decodeURIComponent(aCrumb[1]);}
    }
    return '';
    },setCookie:function(sName,sValue,sExpires){
    var sCookie=sName+"="+encodeURIComponent(sValue);
    if(sExpires!=null){sCookie+="; expires="+sExpires;}
    document.cookie=sCookie;
    },removeCookie:function(sName){
    document.cookie=sName+"=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
    }});
    })(jQuery)$(function(){
    //需要給cookie設置值的時候這樣設置
    $.setCookie("isopen","abc",(1*24*3600)); //判斷cookie是否為空
    _c=$.getCookie("isopen");
    if(_c.length){
    alert('Cookie的值是:'+_c);
    }else{
    var popup = window.open('/main/popup', 'popup', 'top=0,left=0,toolbar=0,directories=0,menubar=0,resizable=0,scrollbars=0,width=300,height=350');
    if(popup){popup.focus();}
    }
    });
    </script>
    </head><body>
    </body>
    </html>