2009년 4월 23일 목요일

[자바스크립트] 팝업창 하루동안 띄우지 않기 소스 및 정중앙에 띄우는 방법

//하루동안 띄우지 않는 소스

팝업창 안에 들어갈 소스는 아래와 같습니다..

//실제 팝업창내의 소스

<html>
<head>
 <title>http://www.blueb.co.kr</title>
<script language="JavaScript">
<!--
function notice_setCookie( name, value, expiredays )
    {
        var todayDate = new Date();
        todayDate.setDate( todayDate.getDate() + expiredays );
        document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
        }

function notice_closeWin()
{
        if ( document.forms[0].Notice.checked )
                notice_setCookie( "Notice", "done" , 1); // 1=하룻동안 공지창 열지 않음
        self.close();
}
function na_call(str){  eval(str);}
//-->
</script>
</head>
<body>
<form name="form1">
<input type="checkbox" name="Notice"  OnClick="notice_closeWin()">오늘은 이창을 다시 열지않음
</form>

</body>
</html>

//본문에 해당하는 문서에 삽입될 소스
<html>
<head>
<title>http://www.blueb.co.kr</title>

<script language="JavaScript">
<!--
function notice_getCookie( name ){
    var nameOfCookie = name + "=";
    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;
                    return unescape( document.cookie.substring( y, endOfCookie ) );
            }
            x = document.cookie.indexOf( " ", x ) + 1;
            if ( x == 0 )
                    break;
    }
    return "";
}
if ( notice_getCookie( "Notice" ) != "done" )
{
        window.open('http://www.blueb.co.kr/SRC/javascript/cookie_popup.html','','width=340,height=300'); // 팝업윈도우의 경로와 크기를 설정 하세요
}
// -->
</script>
</head>

<body>
팝업창을 확인하세요..

</body>
</html>

//화면 정중앙에 팝업 띄우는 소스
<script>
function popUp(w, h){
 x = (screen.availWidth - w) / 2;
 y = (screen.availHeight - h) / 2;
 window.open('http://naver.com', 'pop','width='+w+', height='+h+', left='+x+', top='+y);
}
</script>
<body>
<a href="javascript:popUp(400, 300);">새창띄우기</a>
</body>



//팝업창 왼쪽과 위쪽에 공백이 문제시될 경우

<body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>

댓글 1개: