팝업 띄우기
1. 초기 팝업을 띄울 해당 페이지의 topFrame에 ifame을 hidden('width:0px;height:0px')으로 넣어둔다.
<iframe src='/neo/modules/wp/plugin/pollNotify.mvc?wpId=${wp.wpId}&popupYn=1' style='width:0px;height:0px'></iframe>
2. Java's Service layer에서 popup정보를 조회
3. pollNotify에서 javascript로 쿠키값을 생성 후 팝업을 출력
<script type="text/javascript">
<!--//
var top = 0;
var left = 0;
var windowWidth = window.screen.width;
//팝업정보처리
<c:forEach var="popup" items="${popupInfo}" varStatus="loop">
if(isPopupShowOfCookie('${popup.wp_Id}', '${popup.poll_Id}', '${userId}')){
showPopup('${popup.wp_Id}', '${popup.poll_Id}', '${popup.poll_status}', '${popup.vote_yn}', '${userCheckResult}', '500','300','0', 100, 100);
}
</c:forEach>
//-->
function showPopup(wpId, pollId, pollStatus, voteYn, userCheck, width ,height ,settingCookie, top, left){
var url = "";
if(voteYn=="vote"&&userCheck=="TRUE"){
url="/neo/modules/wp/plugin/pollPluginSubjectVote.mvc?wpId="+wpId+"&pollId="+pollId+"&type="+voteYn+"&checkUser="+userCheck+"&viewType=initPopup"
+"&settingCookie="+settingCookie;
var defaults = {
url: url,
width: "500px",
height: "300px",
top:top,
left:left
}
$.openWin(defaults);
}
}
<%-- 쿠키체크를 통한 팝업표시정보 취득 --%>
function isPopupShowOfCookie(wpId, pollId, userId){
var nameOfCookie = getPopupCookieName(wpId, pollId, userId) + "=";
return chkCookie(nameOfCookie);
}
<%-- 팝업 쿠키 이름 취득 --%>
function getPopupCookieName(wpId, pollId, userId){
return "WP_Poll_Popup_" + wpId+"_" + pollId +"_"+ userId;
}
<%-- 쿠키체크 --%>
function chkCookie(nameOfCookie){
var x = 0;
while ( x <= document.cookie.length ) {
var y = (x+nameOfCookie.length);
if ( document.cookie.substring( x, y ) == nameOfCookie ) {
if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
endOfCookie = document.cookie.length;
if ( unescape( document.cookie.substring( y, endOfCookie ) ) == "hide" )
return false;
}
x = document.cookie.indexOf( " ", x ) + 1;
if ( x == 0 )
break;
}
return true;
}
</script>
4. 팝업에서 "하룻동안 띄우지 않기" 등의 옵션 선택시 팝업에서 쿠키값을 생성
function popupCloseWin(cookieChkBoxId, wpId, pollId, userId, settingCookie){
if( $("#" + cookieChkBoxId ).is(':checked') ){
var name = getPopupCookieName(wpId, pollId, userId);
if( settingCookie == 0 ){//0이면 쿠키 기간을 60일로 설정(기존 로직)
settingCookie = 1;
}
setCookie( name, "hide", settingCookie);
}
window.close();
}
function getPopupCookieName(wpId, pollId, userId){
return "WP_Poll_Popup_" + wpId + "_" + pollId + "_" + userId;
}
function setCookie(name, value, expiredays) {
var toDate = new Date();
toDate.setDate( toDate.getDate() + expiredays );
document.cookie = name + "=" + escape(value) + "; path=/; expires=" + toDate.toGMTString() + ";"
}
5. 팝업의 "하룻동안~"의 닫기 옵션 체크박스를 선택하고 닫기 버튼을 클릭시 팝업에서의 쿠키값을 생성, 초기 팝업을 띄우기 전 생성된 디폴트 쿠키값과 비교하여 팝업 창을 보이지 않도록 한다.