하루동안 새창 열지 않게 하는 소스
메인페이지 접속시 새창을 통한 이벤트공지 및 특정상품 홍보를 위해
많이 사용하는 하루동안 새 창이 열리지 않게 하는 스크립트 소스입니다.
먼저 메인페이지 index.html 새창을 popup.html 이라고 가정하고 아래 순서대로 하시면 됩니다.
1. index.html 파일의 <head></head> 태그를 찾으세요
2. 아래 자바스크립트 소스를 1번 설명에 맞게 넣으시면 됩니다.
<script language="javascript">
function change(form)
{
if (form.url.selectedIndex !=0)
parent.location = form.url.options[form.url.selectedIndex].value
}
function setCookie( name, value, expiredays )
{
var todayDate = new Date();
todayDate.setDate( todayDate.getDate() + expiredays );
document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
function 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 ( getCookie( "Notice" ) != "done" )
{
noticeWindow = window.open('popup.html ','notice','width=300,height=500');
noticeWindow.opener = self;
}
</SCRIPT>
<참고> 바로위에 있는 notice는 팦업창 이름이고 'width=300,height=500'은 팦업창 크기입니다.
3. popup.html 을 만듭니다.popup.html 소스에 아래 자바스크립트를 <head></head>사이에 넣으면 됩니다..
<SCRIPT language="JavaScript">
function setCookie( name, value, expiredays )
{
var todayDate = new Date();
todayDate.setDate( todayDate.getDate() + expiredays );
document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
function closeWin()
{
if ( document.forms[0].Notice.checked )
setCookie( "Notice", "done" , 1);
self.close();
}
</SCRIPT>
<참고> 바로위에 있는 setCookie( "Notice", "done" , 1); 에서 1을 7로 수정하면 7일동안 새창 안뜨게 됩니다. 꼭 하루만 다시 안뜨게 할 필요는 없겠죠^^
4. popup.html 의 아래 소스를 <body></body>사이에 넣어줍니다.
"보통 다시열지 않음" 메세지는 하단부분에 있죠^^
<form>
<input type=CHECKBOX name="Notice" value="">하루동안 다시 열지 않음<br><br>
<a href="javascript:history.onclick=closeWin()">닫기</a>
</form>
'컴퓨터-유용한팁 > HTML' 카테고리의 다른 글
작업표시줄에 원하는 문자 나오게 하기 (0) | 2015.09.06 |
---|---|
배너 랜덤으로 나오게 하는 소스 (0) | 2015.09.06 |
즐겨찾기버튼과 프린터버튼 달기~ (0) | 2015.09.06 |
오른클릭 막아논곳 풀기 (0) | 2015.09.06 |
새창 띄우기 스크립트 (0) | 2015.09.05 |