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


網路上搜尋了一下解決方案,將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"); }
migliori farmacie online 2023: cialis generico – farmacie online sicure
farmacia online migliore: farmacia online miglior prezzo – farmacie online affidabili
farmacie online sicure farmacia online acquisto farmaci con ricetta
https://sildenafilit.bid/# pillole per erezione in farmacia senza ricetta
farmacia online migliore: farmacie online affidabili – top farmacia online
farmacia online piГ№ conveniente: kamagra – farmacie online affidabili
viagra originale in 24 ore contrassegno: viagra consegna in 24 ore pagamento alla consegna – pillole per erezione in farmacia senza ricetta
https://gabapentin.life/# order neurontin
buy paxlovid online: buy paxlovid – paxlovid price
https://wellbutrin.rest/# wellbutrin 75 mg tablet
https://clomid.club/# where can i buy cheap clomid online
32 neurontin: gabapentin best price – neurontin singapore
http://clomid.club/# can i buy clomid online
get clomid online: clomid best price – where can i buy cheap clomid without a prescription
Paxlovid buy online https://paxlovid.club/# paxlovid
https://clomid.club/# get generic clomid tablets
how to get wellbutrin in australia: buy wellbutrin – wellbutrin 15 mg
http://claritin.icu/# buy ventolin online cheap
buy paxlovid online: Paxlovid price without insurance – Paxlovid buy online
https://clomid.club/# how can i get cheap clomid no prescription
over the counter neurontin: cheap gabapentin – medication neurontin
Hi colleagues, hoow is everything, aand whbat youu
desiree tto sayy concerninmg this post, inn my view iits acually awesome iin favor off me.
https://mexicopharmacy.store/# mexican online pharmacies prescription drugs
reputable indian online pharmacy: best india pharmacy – reputable indian online pharmacy
canada online pharmacy: trust canadian pharmacy – cheapest pharmacy canada
http://ordermedicationonline.pro/# canadian neighbor pharmacy legit
onlinecanadianpharmacy safe online pharmacy canadian pharmacy antibiotics
no prescription rx medicine: buy drugs online – my canadian pharmacy rx reviews
Heya i aam ffor tthe fiirst tjme here. I cwme acros this board andd
I fiind It reazlly useful & it helpedd me outt much. I ope to give something backk and aid otjers like you aided me.
buy medicines online in india: top online pharmacy india – india online pharmacy