踩到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"); }
https://buytadalafil.icu/# cheapest tadalafil india
https://stromectolivermectin.pro/# ivermectin 6
https://buytadalafil.icu/# tadalafil
https://stromectolivermectin.pro/# minocycline 50 mg tablets for human
https://pillswithoutprescription.xyz/# canadian medications
buy nexium 40mg generic buy esomeprazole 40mg generic buy sumatriptan for sale
https://pillswithoutprescription.xyz/# prescription drugs
https://stromectolivermectin.pro/# ivermectin over the counter uk
It’s too bad to check your article late. I wonder what it would be if we met a little faster. I want to exchange a little more, but please visit my site baccaratcommunity and leave a message!!
https://buysildenafil.best/# sildenafil buy online usa
help with writing essays for college applications
buy an essay online
buy essay online cheap
https://buysildenafil.best/# best price for generic sildenafil
https://pillswithoutprescription.xyz/# prescription drugs without doctor approval
https://buytadalafil.icu/# buy generic tadalafil online uk
buy minocycline 100 mg tablets minocycline 100mg tablets online
help writing a comparison and contrast essay
essays services
custom essay cheap
minocycline pills stromectol medicine
buy methotrexate generic generic reglan 10mg losartan drug
I was looking for another article by chance and found your article totosite I am writing on this topic, so I think it will help a lot. I leave my blog address below. Please visit once.
custom essays services
the help book essay
buy essay online cheap
order bupropion 150mg without prescription sildenafil over counter viagra sildenafil 25mg
wwwi.odnoklassniki-film.ru
wwwi.odnoklassniki-film.ru
buy an essay cheap
community service essay
order custom essays online
sildenafil 100mg price in india sildenafil gel
how much is generic sildenafil generic viagra sildenafil citrate
please write my essay
college admission essay editing services
essay writer generator
ibuprofen price paxil buy online cheap rocaltrol
easy essay writer
hire essay writer
need help writing an essay
tadalafil online cost tadalafil mexico