테스트 사이트 - 개발 중인 베타 버전입니다

부모창(홈페이지)이 닫힐 때 팝업창이 같이 닫히게 하는 법 알고 싶습니다. 채택완료

김부장1 5년 전 조회 1,845

현재 홈페이지 팝업창을 띄우면 부모창을 종료해도 팝업이 남아 있는데요..

익스플로어에서 새창추가 후 동일한 사이트를 두개 동시띄워도 팝업은 1개만 떠있고,,,24시간이내 다시띄우지 않기 체크하면 팝업창이 실행되지 않는 것을 보니 쿠키는 잘 작동하는 듯 합니다.

 

그런데,, 팝업창이 별도의 창으로 실행되기 때문에  부모창을 닫아도 팝업은 종료가 되지는 않는데요..

혹시 common.js 에 어디 부분을 확인해 봐야할까요?

 

</p>

<p>  function popup_window(url, winname, opt)

    {

        window.open(url, winname, opt);

    }</p>

<p>

    // 폼메일 창

    function popup_formmail(url)

    {

        opt = 'scrollbars=yes,width=417,height=385,top=10,left=20';

        popup_window(url, "wformmail", opt);

    }</p>

<p>    // , 를 없앤다.

    function no_comma(data)

    {

        var tmp = '';

        var comma = ',';

        var i;</p>

<p>        for (i=0; i<data.length; i++)

        {

            if (data.charAt(i) != comma)

                tmp += data.charAt(i);

        }

        return tmp;

    }</p>

<p>    // 삭제 검사 확인

    function del(href) 

    {

        if(confirm("한번 삭제한 자료는 복구할 방법이 없습니다.\n\n정말 삭제하시겠습니까?")) 

            document.location.href = href;

    }</p>

<p>    // 쿠키 입력

    function set_cookie(name, value, expirehours, domain) 

    {

        var today = new Date();

        today.setTime(today.getTime() + (60*60*1000*expirehours));

        document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";

        if (domain) {

            document.cookie += "domain=" + domain + ";";

        }

    }</p>

<p>    // 쿠키 얻음

    function get_cookie(name) 

    {

        var find_sw = false;

        var start, end;

        var i = 0;</p>

<p>        for (i=0; i<= document.cookie.length; i++)

        {

            start = i;

            end = start + name.length;</p>

<p>            if(document.cookie.substring(start, end) == name) 

            {

                find_sw = true

                break

            }

        }</p>

<p>        if (find_sw == true) 

        {

            start = end + 1;

            end = document.cookie.indexOf(";", start);</p>

<p>            if(end < start)

                end = document.cookie.length;</p>

<p>            return document.cookie.substring(start, end);

        }

        return "";

    }</p>

<p>    // 쿠키 지움

    function delete_cookie(name) 

    {

        var today = new Date();</p>

<p>        today.setTime(today.getTime() - 1);

        var value = get_cookie(name);

        if(value != "")

            document.cookie = name + "=" + value + "; path=/; expires=" + today.toGMTString();

    }</p>

<p>    // 이미지의 크기에 따라 새창의 크기가 변경됩니다.

    // zzzz님께서 알려주셨습니다. 2005/04/12

    function image_window(img)

    {

        var w = img.tmp_width; 

        var h = img.tmp_height; 

        var winl = (screen.width-w)/2; 

        var wint = (screen.height-h)/3; </p>

<p>        if (w >= screen.width) { 

            winl = 0; 

            h = (parseInt)(w * (h / w)); 

        } </p>

<p>        if (h >= screen.height) { 

            wint = 0; 

            w = (parseInt)(h * (w / h)); 

        } </p>

<p>        var js_url = "<script type='text/javascript'> \n"; 

            js_url += "<!-- \n"; 

            js_url += "var ie=document.all; \n"; 

            js_url += "var nn6=document.getElementById&&!document.all; \n"; 

            js_url += "var isdrag=false; \n"; 

            js_url += "var x,y; \n"; 

            js_url += "var dobj; \n"; 

            js_url += "function movemouse(e) \n"; 

            js_url += "{ \n"; 

            js_url += "  if (isdrag) \n"; 

            js_url += "  { \n"; 

            js_url += "    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x; \n"; 

            js_url += "    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y; \n"; 

            js_url += "    return false; \n"; 

            js_url += "  } \n"; 

            js_url += "} \n"; 

            js_url += "function selectmouse(e) \n"; 

            js_url += "{ \n"; 

            js_url += "  var fobj      = nn6 ? e.target : event.srcElement; \n"; 

            js_url += "  var topelement = nn6 ? 'HTML' : 'BODY'; \n"; 

            js_url += "  while (fobj.tagName != topelement && fobj.className != 'dragme') \n"; 

            js_url += "  { \n"; 

            js_url += "    fobj = nn6 ? fobj.parentNode : fobj.parentElement; \n"; 

            js_url += "  } \n"; 

            js_url += "  if (fobj.className=='dragme') \n"; 

            js_url += "  { \n"; 

            js_url += "    isdrag = true; \n"; 

            js_url += "    dobj = fobj; \n"; 

            js_url += "    tx = parseInt(dobj.style.left+0); \n"; 

            js_url += "    ty = parseInt(dobj.style.top+0); \n"; 

            js_url += "    x = nn6 ? e.clientX : event.clientX; \n"; 

            js_url += "    y = nn6 ? e.clientY : event.clientY; \n"; 

            js_url += "    document.onmousemove=movemouse; \n"; 

            js_url += "    return false; \n"; 

            js_url += "  } \n"; 

            js_url += "} \n"; 

            js_url += "document.onmousedown=selectmouse; \n"; 

            js_url += "document.onmouseup=new Function('isdrag=false'); \n"; 

            js_url += "//--> \n"; 

            js_url += "</"+"script> \n"; </p>

<p>        var settings;</p>

<p>        if (g4_is_gecko) {

            settings  ='width='+(w+10)+','; 

            settings +='height='+(h+10)+','; 

        } else {

            settings  ='width='+w+','; 

            settings +='height='+h+','; 

        }

        settings +='top='+wint+','; 

        settings +='left='+winl+','; 

        settings +='scrollbars=no,'; 

        settings +='resizable=yes,'; 

        settings +='status=no'; </p>

<p>

        win=window.open("","image_window",settings); 

        win.document.open(); 

        win.document.write ("<html><head> \n<meta http-equiv='imagetoolbar' CONTENT='no'> \n<meta http-equiv='content-type' content='text/html; charset="+g4_charset+"'>\n"); 

        var size = "이미지 사이즈 : "+w+" x "+h;

        win.document.write ("<title>"+size+"</title> \n"); 

        if(w >= screen.width || h >= screen.height) { 

            win.document.write (js_url); 

            var click = "ondblclick='window.close();' style='cursor:move' title=' "+size+" \n\n 이미지 사이즈가 화면보다 큽니다. \n 왼쪽 버튼을 클릭한 후 마우스를 움직여서 보세요. \n\n 더블 클릭하면 닫혀요. '"; 

        } 

        else 

            var click = "onclick='window.close();' style='cursor:pointer' title=' "+size+" \n\n 클릭하면 닫혀요. '"; 

        win.document.write ("<style>.dragme{position:relative;}</style> \n"); 

        win.document.write ("</head> \n\n"); 

        win.document.write ("<body leftmargin=0 topmargin=0 bgcolor=#dddddd style='cursor:arrow;'> \n"); 

        win.document.write ("<table width=100% height=100% cellpadding=0 cellspacing=0><tr><td align=center valign=middle><img src='"+img.src+"' width='"+w+"' height='"+h+"' border=0 class='dragme' "+click+"></td></tr></table>");

        win.document.write ("</body></html></p>

<p>

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트

</p>

<p><script>

function popupOpen() {

    const popup = window.open("popup.html", "popup", "width=200,height=200");

    window.addEventListener('unload', () => {

      if (popup && !popup.closed) {

          popup.close();

      }

    });

}

</script>

<button onclick="popupOpen()">팝업</button></p>

<p>

 

요거 참고하세요

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인