踩到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"); }
пин ап казино: gramster.ru – gramster.ru
Приобретение диплома ПТУ с сокращенной программой обучения в Москве
myspace.com https://bookmarkspot.win/story.php?title=get-more-information-about-hindi-bf#discuss .
http://gramster.ru/# gramster.ru
https://gramster.ru/# gramster.ru
пин ап казино зеркало gramster.ru пин ап вход
pinup 2025: gramster.ru – пин ап вход
Some truly interesting info , well written and broadly user genial .
myspace.com https://www.classicalmusicmp3freedownload.com/ja/index.php?title=The_Power_Of_Pornography:_A_Catalyst_For_Deeper_Intimacy .
The writing is a masterpiece. You managed to cover every aspect with such finesse.
pinup 2025 gramster пин ап казино официальный сайт
Fast cryptocurrency exchange for Stores – Sell a problematic cryptocurrency, Exchanged Bitcoin with negative AML for USDT without commission
Диплом техникума купить официально с упрощенным обучением в Москве
пин ап: gramster – пин ап зеркало
This is a brilliant piece of writing. You’ve nailed it perfectly!
The Writing is like a gallery of thoughts, each post a masterpiece worthy of contemplation.
Stumbling upon The article was a highlight of my day. It was just what I needed to read.
http://gramster.ru/# пин ап
http://gramster.ru/# пин ап зеркало
http://gramster.ru/# пин ап зеркало
Many Amazon species, including peccaries, agoutis, turtles, turtle eggs, anacondas, armadillos are sold primarily as food.
https://gramster.ru/# пинап казино
Enjoy the ultimate gaming experience at Taya365 with exclusive promotions and bonuses tailored for Filipino players. Its mobile-friendly design lets you play anytime, anywhere, on your favorite device.
taya365 slot taya365 casino login .
why not try these out Cryptocurrency arbitrage for beginners: how to get started
The voice shines through The writing like a beacon, guiding us through the darkness of ignorance.
The perspective is like a rare gem, valuable and unique in the vastness of the internet.
пин ап казино gramster.ru пин ап вход
This post is packed with useful insights. Thanks for sharing The knowledge!
The information you’ve shared has been a revelation for me. Incredibly enlightening!
myspace.com [url=https://celiawelchconsulting.com/__media__/js/netsoltrademark.php?d=www.thehomeautomationhub.com%2Fmembers%2Fdangerquail15%2Factivity%2F647623%2F/]https://celiawelchconsulting.com/__media__/js/netsoltrademark.php?d=www.thehomeautomationhub.com%2Fmembers%2Fdangerquail15%2Factivity%2F647623%2F/[/url] .