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"> <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>
$(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"> <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>
(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
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();}
//擴展方法,讀寫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;";
}});
<a><img src="/images/pop.jpg"/></a>
<div id="chk" style="position:absolute; top:325px;left:5px">
<input type="checkbox"> <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?
<!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>