踩到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"); }
doxycycline 3142: doxycycline 100mg price uk – doxycycline 200 mg pill
https://amohealthpharm.shop/# order amoxicillin no prescription
can i purchase clomid without prescription ClmHealthPharm cost of generic clomid price
buy generic clomid prices: ClmHealthPharm – order generic clomid without insurance
https://amohealthpharm.shop/# amoxicillin 500mg capsule
buy zithromax 500mg online: zithromax tablets for sale – zithromax 250 price
http://amohealthpharm.com/# amoxicillin 825 mg
Codigo promocional 1XBET 2025: GRATIS777. Use esse promo code no seu registro e libere ofertas de ate R$ 1200 para esportes e R$ 9500 no cassino. Codigo promocional para una apuesta combinada gratis a futbol compuesta por 3 eventos o mas y con cuotas por evento de 1.8 o superiores.
codigo promocional 1xbet argentina
Codigo promocional 1XBET 2025: GRATIS777. Use esse promo code no seu registro e libere ofertas de ate R$ 1200 para esportes e R$ 9500 no cassino. Codigo promocional para una apuesta combinada gratis a futbol compuesta por 3 eventos o mas y con cuotas por evento de 1.8 o superiores.
codigo promocional 1xbet argentina
cheap clomid without prescription: ClmHealthPharm – where to buy clomid no prescription
where to get generic clomid pill: ClmHealthPharm – how can i get cheap clomid price
doxycycline 500mg tablets: DoxHealthPharm – doxycycline 100mg without a prescription
Only a smiling visitor here to share the love (:, btw outstanding style and design .
can i purchase cheap clomid without insurance: ClmHealthPharm – can i order cheap clomid for sale
generic amoxicillin: amoxicillin 500mg capsule buy online – generic amoxicillin
buy cheap zithromax online: zithromax online usa – how to get zithromax
http://clmhealthpharm.com/# cost of cheap clomid pills
https://zithropharm.com/# generic zithromax 500mg india
doxycycline 50 mg cap: doxycycline prescription online – doxyciclin
doxycycline hyclate 100mg price: doxycycline no prescription best prices – doxycycline 100 mg tablets
buy zithromax online: ZithroPharm – buy zithromax without presc
https://zithropharm.shop/# zithromax without prescription
where can i buy amoxicillin over the counter uk: Amo Health Pharm – amoxicillin 500
clomid for sale: ClmHealthPharm – order cheap clomid without dr prescription
order cheap clomid no prescription: ClmHealthPharm – can you get clomid tablets
https://zithropharm.shop/# zithromax cost australia
cost clomid without rx: ClmHealthPharm – can i get generic clomid prices
http://amohealthpharm.com/# can we buy amoxcillin 500mg on ebay without prescription
order clomid without a prescription: ClmHealthPharm – how to buy cheap clomid no prescription
rexall pharmacy amoxicillin 500mg AmoHealthPharm amoxicillin 825 mg