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

18,607 Responses

  1. Секреты успешной покупки входной металлической двери, соответствует всем требованиям безопасности.
    Лучшие магазины с широким выбором входных металлических дверей.
    входная дверь дверь металлическая .

    Советы по избежанию ошибок при покупке металлической входной двери.
    5 основных причин купить металлическую входную дверь.
    В чем отличия входных металлических дверей разных производителей.

  2. MichaelUsaws表示:

    https://farmatadalitaly.shop/# Farmacie online sicure
    migliori farmacie online 2024

  3. Edwardopele表示:

    farmacia online piГ№ conveniente: Ibuprofene 600 prezzo senza ricetta – acquisto farmaci con ricetta

  4. MichaelUsaws表示:

    http://farmasilditaly.com/# viagra 50 mg prezzo in farmacia
    farmacie online autorizzate elenco

  5. NathanSal表示:

    comprare farmaci online con ricetta Ibuprofene 600 prezzo senza ricetta acquistare farmaci senza ricetta

  6. Clinterete表示:

    https://farmaprodotti.com/# Farmacia online piГ№ conveniente
    Farmacia online miglior prezzo

  7. BradleyThine表示:

    Farmacia online piГ№ conveniente: Farma Prodotti – farmaci senza ricetta elenco
    farmacie online autorizzate elenco

  8. NathanSal表示:

    esiste il viagra generico in farmacia viagra senza prescrizione kamagra senza ricetta in farmacia

  9. BradleyThine表示:

    viagra online spedizione gratuita: Viagra – viagra 100 mg prezzo in farmacia
    Farmacie on line spedizione gratuita

  10. Stevespork表示:

    Deepika Padukone and Christy Turlington star in landmark Sabyasachi fashion show
    жесткое порно бесплатно
    Camera phones at the ready, around 700 guests hailing from across India and the world expected a visual spectacle on Saturday evening — and they weren’t disappointed. A hush descended as the doors opened to the Jio World Center in Mumbai, where legendary Indian fashion designer Sabyasachi Mukherjee presented a star-studded 25th anniversary runway show for his namesake brand.

    The celebrated designer — known for his maximalist Indian style — has dressed some of the biggest names across Bollywood and Hollywood, including Priyanka Chopra, Deepika Padukone, Oprah Winfrey, Rihanna and Jennifer Lopez. For his landmark show, the stars showed up to lend their support: Padukone opened proceedings in an all-white ensemble adorned with necklaces, including a crucifix from Mukherjee’s jewelry line. She later walked again with supermodel Christy Turlington as part of the grand finale.
    Over 150 looks were presented, including pants and skirts embroidered with gold threads, frilled head gear, stacked jewelry and tops with slogans such as “cat lady,” “table for one,” “where has love gone,” and “all dressed up nowhere to go.” Mukherjee explained in a phone interview that these pieces were intended to be satire on how technology is dehumanizing humans. “We seem to have forgotten how to establish human relationships,” he said.
    There were also trench coats, sweaters, shorts and shirts made in more conventionally western silhouettes. These marked a departure from Mukherjee’s usual festive and bridal wear, which are heavily inclined towards traditional Indian styles, such as saris, ghagra cholis and sherwanis.

    But with no shortage of drama, the new collection featured heavily embroidered jackets embellished with semi-precious stones, brocade dresses, ostrich leather jackets and skirts, and blouses with velvet appliques overlaid with faux fur.

  11. Clinterete表示:

    https://farmaprodotti.com/# Farmacie online sicure
    farmacie online affidabili

  12. Edwardopele表示:

    top farmacia online: Farm Tadal Italy – п»їFarmacia online migliore

  13. Edwardopele表示:

    farmaci senza ricetta elenco: Tadalafil generico migliore – farmacia online senza ricetta

  14. BradleyThine表示:

    farmaci senza ricetta elenco: Farm Tadal Italy – farmacia online senza ricetta
    farmacia online

  15. MichaelUsaws表示:

    https://farmasilditaly.shop/# viagra generico prezzo piГ№ basso
    Farmacia online miglior prezzo

  16. NathanSal表示:

    farmacia online farmacie online affidabili farmaci senza ricetta elenco

  17. Kasyna na całym świecie próbują przyciągnąć graczy różnymi sposobami, w tym oferując bonusy bez depozytu, jak darmowe spiny bez depozytu za rejestrację. Free spiny to obroty bębnami, podczas których nie jest pobierana gotówka z salda gracza. Aby nie ponosić strat, kasyna wprowadziły wymagania związane z obrotem wygraną z bonusów bez depozytu. Darmowe spiny bez depozytu za rejestrację są alternatywą do bonusów gotówkowych, które daje kasyno online za rejestrację. W tym tekście przejrzymy się szczegółowo wszystkim kwestiom związanym z darmowymi spinami bez depozytu.

  18. Jesteśmy ekspertami w branży polskiego hazardu — konsultujemy graczy w pytaniach, jaki bonus czy jaką grę wybrać na start. Dbamy, by gracze byli dobrze poinformowani: mogli przeczytać recenzję gry, zdobyć bonusy bez depozytu czy poznać polecane kasyna bez depozytu. Oferujemy wiele tytułów gier hazardowych za darmo, w jakie można zagrać całkowicie bez ryzyka. Ale podstawową rzeczą, która wabi wszystkich naszych czytelników, jest bonus bez depozytu. Czym różni się kasyno bez depozytu od zwykłego? Gdzie jest dostępny bonus jako darmowa kasa za rejestrację bez depozytu? Opowiemy w dalszej części artykułu.

  19. Clinterete表示:

    https://farmatadalitaly.com/# farmacie online autorizzate elenco
    Farmacia online piГ№ conveniente

  20. MichaelUsaws表示:

    https://farmatadalitaly.com/# comprare farmaci online con ricetta
    farmacia online piГ№ conveniente

  21. MichaelUsaws表示:

    https://farmabrufen.shop/# BRUFEN 600 acquisto online
    farmacia online senza ricetta

  22. Clinterete表示:

    https://farmatadalitaly.shop/# top farmacia online
    farmacia online

  23. BradleyThine表示:

    miglior sito per comprare viagra online: Farma Sild Italy – viagra prezzo farmacia 2023
    acquisto farmaci con ricetta

  24. BradleyThine表示:

    farmacie online autorizzate elenco: Farma Brufen – farmacie online autorizzate elenco
    farmacia online

  25. 190425 734101As I internet website possessor I believe the content matter here is rattling magnificent , appreciate it for your hard work. You must maintain it up forever! Finest of luck. 360277

  26. Franktaurl表示:

    A brief history of sunglasses, from Ancient Rome to Hollywood
    Площадка кракен

    Sunglasses, or dark glasses, have always guarded against strong sunlight, but is there more to “shades” than we think?

    The pupils of our eyes are delicate and react immediately to strong lights. Protecting them against light — even the brilliance reflected off snow — is important for everyone. Himalayan mountaineers wear goggles for this exact purpose.

    Protection is partly the function of sunglasses. But dark or colored lens glasses have become fashion accessories and personal signature items. Think of the vast and famous collector of sunglasses Elton John, with his pink lensed heart-shaped extravaganzas and many others.

    When did this interest in protecting the eyes begin, and at what point did dark glasses become a social statement as well as physical protection?
    The Roman Emperor Nero is reported as holding polished gemstones to his eyes for sun protection as he watched fighting gladiators.

    We know Canadian far north Copper Inuit and Alaskan Yupik wore snow goggles of many kinds made of antlers or whalebone and with tiny horizontal slits. Wearers looked through these and they were protected against the snow’s brilliant light when hunting. At the same time the very narrow eye holes helped them to focus on their prey.

    In 12th-century China, judges wore sunglasses with smoked quartz lenses to hide their facial expressions — perhaps to retain their dignity or not convey emotions.

  27. Williambob表示:

    They’ve sailed across Southeast Asia for centuries. Now, these sea nomads are being forced to live on land
    скупка прицело ночного виденья
    Bilkuin Jimi Salih doesn’t remember how old he was when he learned to dive, only, that all the men in his family can do it.

    It might have been his grandfather who taught him, or his father, or even an uncle or cousin. He recalls swimming dozens of feet underwater among the reefs, collecting spider conches, abalone and sea cucumbers to sell at the local fish market.

    “One of our specialties is that, because we live on the sea and we’re always in the sea, we can dive in the water for a long time,” says Salih, via a translator. “We learn by observing, and from there, we develop our own technique.”

    To most people, Salih’s free diving skills are highly unusual; but not to his community. Salih is Bajau Laut, an indigenous seafaring group in Southeast Asia that has lived a semi-nomadic lifestyle on the ocean for centuries. Living on boats and fishing for income and sustenance, the Bajau Laut aren’t just reliant on the sea: they’re biologically adapted to it, with larger spleens that give them the ability to hold their breath for far longer than the average person.

    “We’re very comfortable in the water,” says Salih. The 20-year-old was born on board a lepa, a type of houseboat, on the shore of Omadal Island, off the coast of Semporna in Malaysian Borneo.

  28. Clinterete表示:

    https://farmaprodotti.com/# farmacie online affidabili
    Farmacia online miglior prezzo

發佈留言

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