踩到Window resize在Preview print的雷

最近在作案的過程中遇到一個狀況,從Art design那邊拿到的頁面,會在Window resize的時候執行某個Function,本來一切都正常,但測試到Chrome和Firefox預覽列印時發現也會Trigger這個Event,會讓在預覽列印過後的頁面發生問題,所以必須要進行修正,以下是這個案例的說明:

先在測試頁加入以下的程式,發現在預覽列印的時候會Trigger window resize event:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Preview Print Test</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script>
        $(window).resize(function() {
            console.log("Window Resize");
        });
    </script>
</head>
<body>
<h1>Window Resize Test</h1>
</body>
</html>
Preview print trigger window resize event
Preview print trigger window resize event

網路上搜尋了一下解決方案,將Script改寫如下,可以順利解決,但不知道是不是最好的方法,如果大家有更好的也別忘了告訴我唷~

openResizeFn();

// Chorme
var print = false;
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function (mql) {
    if (mql.matches) {
        closeResizeFn();
    } else {
        setTimeout(openResizeFn, 2000);
    }
});

// Firefox
window.onbeforeprint = function () {
    closeResizeFn();
};
window.onafterprint = function () {
    setTimeout(openResizeFn, 2000);
};

// Common Function
function openResizeFn() {
    $(window).on("resize", windowResize);
}

function closeResizeFn() {
    $(window).off("resize", windowResize);
}

function windowResize() {
    console.log("Window Resize");
}

You may also like...

5,658 Responses

  1. Zieezt表示:

    buy atorvastatin 40mg generic generic tenormin 100mg buy lyrica 75mg online

  2. Martypisn表示:

    help with scholarship essays
    what is the best essay writing service
    who can i pay to write my essay

  3. Calvindit表示:

    natural ed medications erection pills online

  4. Zvulqc表示:

    buy tizanidine 2mg generic cialis 5mg cheap cialis overnight shipping usa

  5. Dorolisapisn表示:

    what are the best essay writing services
    medical school essay service
    what is the best custom essay site

  6. Calvindit表示:

    best canadian pharmacy to buy from cheap viagra canadian pharmacy

  7. Marrispisn表示:

    easy essay writer
    top 10 essay writing services
    essay writing services singapore

  8. Joetepisn表示:

    dating apps free
    dating web site
    local free chatline

  9. Wroltb表示:

    purchase zetia generic buy motilium 10mg online cheap baclofen 10mg canada

  10. engelsWet表示:

    What should I do if I have trichomoniasis. doxycycline dog How allergies impact your dog s quality of life.

  11. BrandonVam表示:

    buying doxycycline online in usa can you buy doxycycline over the counter australia

  12. Willietwict表示:

    https://ed-pills.xyz/# cheapest ed pills online

  13. Eachellepisn表示:

    dating site for free
    free online dating site
    dating sims free online japanese adult

  14. Brianagite表示:

    https://24hr-pharmacy.top/# canadian prescription drugs

  15. engelsWet表示:

    doxycycline for cellulitis dose Balducci C, Santamaria G, La Vitola P, Brandi E, Grandi F, Viscomi AR, Beeg M, Gobbi M, Salmona M, Ottonello S, Forloni G.

  16. MichaelBlibe表示:

    buy clomiphene clomid

  17. engelsWet表示:

    doxycycline warnings For many years the only option for patients with visually significant Fuchs dystrophy was a full thickness corneal transplant or penetrating keratoplasty PKP.

  18. Brianagite表示:

    https://24hr-pharmacy.top/# how to order prescription drugs from canada

  19. Arreple表示:

    Shah BK, Sharma S, Shakya G, Upadhyay BP. how long do doxycycline side effects last What is Doxycycline HYC 100mg used for.

  20. Yczhjx表示:

    buy oxcarbazepine 300mg pill order crestor 20mg without prescription rosuvastatin 10mg for sale

  21. wewencash表示:

    Also, 40 mL of 2 lidocaine is given to effect anesthesia from the initial excitation. doxycycline hyclate 100mg

  22. wewencash表示:

    i want to buy doxycycline 100mg P P P a; d, inset; f; i are 10 Ојm.

  23. wewencash表示:

    doxycycline and pregnancy How Does Doxycycline Work.

  24. Maisiepisn表示:

    local women dates
    ourtime logga in
    freetalk45

  25. MichaelBlibe表示:

    cost of doxycycline in india 631311 doxycycline

  26. engelsWet表示:

    what does doxycycline look like The type 2 diabetes statistics by state tiger was also very responsive, and suddenly avoided the python is first attack with a jump, but the python would naturally not give up when it suffered, and then frantically bit the other side again.

  27. arrindCen表示:

    doxycycline 100mg acne I get the SPF 15, but they have a lot of options.

  28. MichaelBlibe表示:

    doxycycline cost canada buy doxycycline over the counter uk

  29. Arreple表示:

    Similarly, when the dose is lowered to a maintenance level or to be discontinued, the amount should be reduced gradually over four or five days. what is doxycycline 18, 376 379 2012.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。