ページがかわったら小窓を消すjavascript

画像やPDFの表示など小窓を使った制御。ページが変わると同時に開いていた小窓をけすことができます。使う用途はあるとおもいます。

ページが遷移したら開いていた小窓を閉じる

サンプル
https://blog.tama-tama.net/test/komado/

<script>
$(function(){
    window.onunload = function() {

        CloseWindow1();
        //CloseWindow2();
        //CloseWindow3();
        //CloseWindow4();
    }
 
    var
    w       = 770,
    h       = 600,
    l       = (screen.availWidth - w) / 2,
    t       = (screen.availHeight - h) / 2,

    popPage1 = '.popup1';
    $(popPage1).on('click',function(event){
        p1 =window.open(this.href,"window1","width= "+ w + ",height=" + h + ",left=" + l + ",top=" + t + ", scrollbars = yes, location = no, toolbar = no, menubar = no, status = no");
         return false;
    });
/*    増やす場合
popPage2 = '.popup2';
    $(popPage2).on('click',function(event){
        p2 =window.open(this.href,"window2","width= "+ w + ",height=" + h + ",left=" + l + ",top=" + t + ", scrollbars = yes, location = no, toolbar = no, menubar = no, status = no");
         return false;
    });
    popPage3 = '.popup3';
    $(popPage3).on('click',function(event){
        p3 =window.open(this.href,"window3","width= "+ w + ",height=" + h + ",left=" + l + ",top=" + t + ", scrollbars = yes, location = no, toolbar = no, menubar = no, status = no");
         return false;
    });
    popPage4 = '.popup4';
    $(popPage4).on('click',function(event){
        p4 =window.open(this.href,"window4","width= "+ w + ",height=" + h + ",left=" + l + ",top=" + t + ", scrollbars = yes, location = no, toolbar = no, menubar = no, status = no");
         return false;
    });

*/


   // CLOSE
    function CloseWindow1() {
        if (typeof p1 != "undefined") {
            p1.close();
        }
        }
/*増やす場合
    function CloseWindow2() {
        if (typeof p2 != "undefined") {
            p2.close();
        }
        }
    function CloseWindow3() {
        if (typeof p3 != "undefined") {
            p3.close();
        }
        }
    function CloseWindow4() {
        if (typeof p4 != "undefined") {
            p4.close();
        }
        }

*/

});

</script>

コメント

hage01

2008年頃からワードプレス使ってますヴァージョンは2.6か2.8かだったかな?

hage01をフォローする
タイトルとURLをコピーしました