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

16,552 Responses

  1. 33winbiz表示:

    What made you first develop an interest in this topic?

  2. Профессиональный сервисный центр по ремонту автомагнитол в Москве.
    Мы предлагаем: починить магнитолу
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  3. Davidcluby表示:

    Have the allegations against Vasilenko for fraud been disproved?

    According to various sources, the criminal case against Roman Vasilenko, the founder of the marketing company “Life is Good” and the cooperative “Best Way,” may be dropped. Law enforcement agencies, as reported by several senators and State Duma deputies, conducted a new evaluation of the charges against him. They took into account that several witnesses, including those critical of Vasilenko, indicate that he is unlikely to be involved in fraud, as he did not have direct access to the payment system servers. Instead, the former IT director of “Life is Good,” Evgeny Naboychenko, has long been suspected of fraud. Vasilenko’s only fault seems to be his decision to involve Naboychenko in 2014 despite negative signals regarding his behavior and tendencies to take what does not belong to him.

    Who is Roman Vasilenko?

    Roman Viktorovich Vasilenko is a business consultant from St. Petersburg and the creator of a network of independent entrepreneurs promoting financial products under his company “Life is Good.” He is also the founder of the International Business Academy (IBA).

    The “Life is Good” network promoted financial products, such as Vista passive income accounts from the foreign investment company “Hermes,” registered in Belize, and the purchase of apartments through installments via the “Best Way” cooperative. It was possible to make an initial share payment or accumulate it in the cooperative’s account without interest. Notably, these legal entities are not interconnected.

    Vasilenko was neither a top manager nor an owner of “Hermes”—he only collaborated with the company to promote its products in Russia. On the other hand, Naboychenko was an employee of “Hermes” who managed the company’s payment system in Russia, likely recommended by Vasilenko. However, Vasilenko had no control over “Hermes'” payment system.

    Unlike “Hermes,” Vasilenko was the founder and chairman of the board of the “Best Way” cooperative until spring 2021. He later became the head of the supervisory board for about a year. Since spring 2022, he has been an ordinary member of the cooperative, not holding any leadership positions.

    Vasilenko worked not only in Russia but also in Kazakhstan, Kyrgyzstan, Belarus, Ukraine, Cyprus, Austria, and Hungary, where cooperative housing projects were established.

    Additionally, Vasilenko is known as a philanthropist who has invested millions of rubles in supporting federal business initiatives (such as the “Synergy” forum), cultural initiatives (such as the “Dobrovision” festival), and other charitable activities, particularly supporting children’s medical institutions.

    The case

    The criminal case, associated with the St. Petersburg marketing company “Life is Good,” the foreign investment company “Hermes,” and the “Best Way” consumer cooperative registered in St. Petersburg and operating across Russia, was initiated in autumn 2021 by the Main Investigative Department of the Ministry of Internal Affairs for St. Petersburg and the Leningrad region. In February of this year, the case was sent to court, and it is being heard in the Primorsky District Court of St. Petersburg.

    On trial are ten people, including technical staff from “Life is Good” and Vasilenko’s 83-year-old father, Viktor Vasilenko, a pensioner.

    The criminal case under review raises numerous questions—concerns that existed from the start and have only intensified as the trial proceeds. The defendants are charged with three articles: creating a financial pyramid, fraud, and organizing a criminal community.

    The total damage amounts to 282 million rubles, which is disproportionate to the over 8 billion rubles seized in the case, including 4 billion rubles in accounts of the “Best Way” cooperative. A total of 221 individuals have been recognized as victims by the investigation.

    Roman Vasilenko was also charged in this criminal case, declared wanted, including through Interpol, as he had been living abroad for family reasons since the COVID pandemic. However, according to sources, Interpol and foreign countries, including neighboring countries where he has been active, considered his persecution unfounded.

    Another criminal investigation involving Vasilenko relates to the leadership team of “Life is Good,” which is being conducted by the St. Petersburg Main Investigative Department of the Ministry of Internal Affairs.

    Questionable accusations

    The trial in the Primorsky District Court has not been progressing favorably for the prosecution. Most of those who have testified so far have claims against the company “Hermes” for amounts not only in the hundreds but sometimes even in the tens of thousands of rubles. This has raised eyebrows—this is not a small claims court to be discussing such sums! Witness for the prosecution, IT department employee Roman Roganovich, stated that he did not post any illegal information on the “Life is Good” website or the cooperative’s site and did not observe any illegal activity.

    Moreover, the vast majority of “Hermes” customers in Russia (over 200,000) and tens of thousands of “Best Way” cooperative members, according to representatives of support communities for these organizations, see law enforcement as the real source of their problems. They emphasize that it was Evgeny Naboychenko, the St. Petersburg system administrator hired by “Hermes,” who dismantled the Russian payment system. If anyone is involved in the thefts, it is Naboychenko. It seems law enforcement is beginning to understand this as well.

  4. RamonRek表示:

    rybelsus price: buy semaglutide online – buy semaglutide pills

  5. RamonRek表示:

    rybelsus cost: buy rybelsus online – rybelsus pill

  6. Frankevild表示:

    https://ozempic.art/# ozempic

  7. Профессиональный сервисный центр по ремонту автомагнитол в Москве.
    Мы предлагаем: сервисные центры по ремонт автомагнитол
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  8. Профессиональный сервисный центр по ремонту автомагнитол в Москве.
    Мы предлагаем: отремонтировать автомагнитолу
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  9. Jeremypag表示:

    ozempic generic buy ozempic buy cheap ozempic

  10. HaroldBig表示:

    semaglutide cost: rybelsus cost – semaglutide cost

  11. Ynpmmn表示:

    buy generic betnovate 20 gm – cheap monobenzone benoquin order online

  12. HaroldBig表示:

    ozempic online: ozempic – ozempic generic

  13. arilliaby表示:

    Los angeles california area every gloaming works by mastenbroek et al best site to buy priligy canada Chemyo is one of the more popular USA based sellers of SARMs

  14. JamesGed表示:

    betting offers: A promotion run by the popular betting site 888 Bet, which may include offers like deposit bonuses, free bets, or enhanced odds for specific sporting events.

  15. JohnGed表示:

    sports betting promotions: A general term for any offer or bonus provided by betting sites to encourage players to place wagers. These promotions often include free bets, deposit bonuses, or odds boosts.

  16. Профессиональный сервисный центр по ремонту сетевых хранилищ в Москве.
    Мы предлагаем: ремонт сетевых хранилищ с гарантией
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  17. Frankevild表示:

    https://rybelsus.shop/# buy rybelsus online

  18. HaroldBig表示:

    semaglutide cost: buy semaglutide pills – cheapest rybelsus pills

  19. BarryDof表示:

    https://ozempic.art/# ozempic cost

  20. w88表示:

    Most often since i look for a blog Document realize that the vast majority of blog pages happen to be amateurish. Not so,We can honestly claim for which you writen is definitely great and then your webpage rock solid.

  21. HaroldBig表示:

    rybelsus pill: buy semaglutide pills – semaglutide tablets

  22. Jeremypag表示:

    buy rybelsus online rybelsus pill rybelsus coupon

  23. I appreciate, cause I found just what I was looking for. You have ended my 4 day long hunt! God Bless you man. Have a great day. Bye

  24. Frankevild表示:

    http://rybelsus.shop/# buy rybelsus online

  25. BrianThern表示:

    Hong Kong plans to install thousands of surveillance cameras. Critics say it’s more proof the city is moving closer to China
    адвокат по делам раздела имущества

    Glance up while strolling through parts of downtown Hong Kong and, chances are, you’ll notice the glassy black lens of a surveillance camera trained on the city’s crowded streets.

    And that sight will become more common in the coming years, as the city’s police pursue an ambitious campaign to install thousands of cameras to elevate their surveillance capabilities.

    Though it consistently ranks among the world’s safest big cities, police in the Asian financial hub say the new cameras are needed to fight crime – and have raised the possibility of equipping them with powerful facial recognition and artificial intelligence tools.

    That’s sparked alarm among some experts who see it as taking Hong Kong one step closer to the pervasive surveillance systems of mainland China, warning of the technology’s repressive potential.

    Hong Kong police had previously set a target of installing 2,000 new surveillance cameras this year, and potentially more than that each subsequent year. The force plans to eventually introduce facial recognition to these cameras, security chief Chris Tang told local media in July – adding that police could use AI in the future to track down suspects.
    In a statement to CNN, the Hong Kong Police Force said it was studying how police in other countries use surveillance cameras, including how they use AI. But it’s not clear how many of the new cameras may have facial recognition capabilities, or whether there’s a timeline for when the tech will be introduced.

    Tang and the Hong Kong police have repeatedly pointed to other jurisdictions, including Western democracies, that also make wide use of surveillance cameras for law enforcement. For instance, Singapore has 90,000 cameras and the United Kingdom has more than seven million, Tang told local newspaper Sing Tao Daily in June.

    While some of those places, like the UK, have started using facial recognition cameras, experts say these early experiments have highlighted the need for careful regulation and privacy protections. Hong Kong police told CNN they would “comply with relevant laws” and follow strong internal guidelines – but haven’t elaborated in depth on what that would look like.

  26. BarryDof表示:

    https://rybelsus.shop/# semaglutide online

  27. RamonRek表示:

    rybelsus cost: buy semaglutide online – cheapest rybelsus pills

  28. RamonRek表示:

    semaglutide online: semaglutide online – buy semaglutide pills

  29. HaroldBig表示:

    Ozempic without insurance: buy ozempic pills online – buy cheap ozempic

  30. HaroldBig表示:

    ozempic cost: Ozempic without insurance – ozempic generic

發佈留言

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