踩到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...

17,232 Responses

  1. неотложная наркологическая помощь в москве неотложная наркологическая помощь в москве .

  2. скорая наркологическая помощь на дому в москве https://www.sportandpolitics.ukrbb.net/viewtopic.php?f=24&t=17890 .

  3. xcgqtyfaa表示:

    By Elle Turner If you’re looking for a two-in-one brow tool that let’s you get away with doing your eyebrows on your morning commute, well, this is the one. The babassu in the formula keeps your eyebrows feeling soft and waxy rather than hard and crunchy, and the thin pencil is great for filling in those hard-to-reach spots. —T.A. When I dyed my hair from its natural dark brown to a lighter brown with red undertones, the color clashed with my eyebrows. This brow pencil range had the most options for me to try in search of the perfect match. Not only does it have the creamiest formula ever, but the tip of the applicator is great for precise lines and edges. The best part is the dense brush on one end—it blends my brows to perfection—that took the number of tools I was using on my brows from three to one. —K.H.
    http://www.genina.com/user/profile/4454629.page
    Yes, we do! View our list of services. Birthday celebrations, engagement sessions, parties, or photoshoots—we have hair and makeup artists available for any type of event. We’re also available for editorial, commercial, and runway work. Our hair and makeup artists will travel to your location, or you can come to us at L Style Bar, our Denver blow dry bar and makeup studio. When visiting The Right Hair Salon, you are immediately greeted by the welcoming smile of Gina; our exceptional front desk staff. Their job is to make sure you have the most enjoyable salon experience possible and are happy to answer any questions, offer refreshments or book appointments. Glo Girl Salon is located at 22191 Powerline Road, Suite 18B, Boca Raton, Florida, 33433. We are open Monday through Friday, 7:30am until 7:00pm, and Sundays 10am until 5:00pm. We are closed on Saturdays. We make it easy for you to book the services you need directly on our website – simply click our online scheduling link to schedule your service appointment online, or call 561-500-8456 to schedule your appointment!

  4. Pkbet表示:

    Hey very cool site!! Man .. Beautiful .. Amazing .. I will bookmark your website and take the feeds also…I’m happy to find so many useful information here in the post, we need develop more strategies in this regard, thanks for sharing. . . . . .

  5. частная скорая наркологическая помощь http://www.klin.0pk.me/viewtopic.php?id=4428/ .

  6. Barrybib表示:

    п»їcialis generic: MaxPillsForMen – cialis for sale

  7. как вызвать наркологическую скорую помощь в москве klin.0pk.me/viewtopic.php?id=4428 .

  8. BrettTIT表示:

    п»їcialis generic: MaxPillsForMen – Tadalafil price

  9. jllmdmeku表示:

    It’s So BIG Volumizing Mascara Trending price is based on prices over last 90 days. Enhances mascara Verified purchase: Yes | Condition: New As well as a visible difference in length, I also noticed that my mascara stayed on much better with the primer. I’ll be honest with you, my Paradise mascara was a bit old and nearing the end of it’s life, so by 5pm it had definitely started to leave a few crusty specks on my cheek just because the formula was dried out. But the primer seemed to really revive it and I had zero flaking when I used the two together. Best Mascara Primers It’s So BIG Volumizing Mascara With 4 weeks of use: It strengthens your eyelashes, embellishes them and improves the elasticity, encouraging maximum growth. Your shopping cart is empty! Then apply a coat of your favorite mascara. I recently switched to tubing mascara which you can learn more about my favorites here.
    https://jobs251.com/author/blogovrala1976/
    Your cart is empty ‘The brush itself is of similar quality to the ZOEVA brushes, which are nearly three times the price. The bristles are very soft and create a layer of foundation over the skin, giving a flawless effect rather than pushing the foundation into the pores. You also end up using less foundation as I find it doesn’t seem to disappear into the bristles.’ Tapered foundation brushes are usually flat, less full in form, with a gentle taper. These brushes are best for liquid foundation and other liquid products. If you are having trouble deciding on a type of foundation, learn more about the different types of foundation here. To use, start by dipping your brush in warm water then gently squeezing out the excess. If it’s hot and you’re prone to sweating, use cool water for a more refreshing application experience.

  10. BrettTIT表示:

    Cialis 20mg price: Buy Cialis online – Cialis without a doctor prescription

  11. Donaldabula表示:

    Viagra online price buy viagra online Cheap generic Viagra

  12. Great blog here! Additionally your website rather a lot up very fast! What host are you the usage of? Can I get your associate link for your host? I desire my website loaded up as fast as yours lol

  13. RogerFaf表示:

    https://maxpillsformen.com/# Generic Cialis price

  14. RogerFaf表示:

    https://fastpillsformen.com/# Generic Viagra online

  15. неотложная наркологическая помощь в москве неотложная наркологическая помощь в москве .

  16. как вызвать наркологическую скорую помощь в москве как вызвать наркологическую скорую помощь в москве .

  17. New 88表示:

    This will be helpful for my family.

  18. BrettTIT表示:

    Buy Viagra online cheap: buy viagra online – best price for viagra 100mg

發佈留言

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