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

26,039 Responses

  1. Pingidiof表示:

    dark web market urls https://github.com/aresonioncq0a7/aresonion – best darknet markets

  2. Danieljak表示:

    “Every morning I come downstairs and he’s already done the dishwasher, he’s already packed his lunch, and he’s ready to go,” Ruthe’s father, Ben, tells CNN Sports.

    “He’s just a disciplined kid. He goes to bed early, he looks after himself, he eats well, he looks after his sister. He’s just a good kid around the house in all ways, really. We’re very lucky.”
    pendle finance
    Ruthe is next due to compete in the 1,500 meters at the Maurie Plant Meet in Melbourne on Saturday, and one target time to aim for will be his dad’s fastest time of 3:41.22 – three hundredths of a second faster than Ruthe’s current personal best.
    But he still has a way to go before he can call himself the most decorated runner in his family. Dad Ben and mom Jess are both former national champions who represented New Zealand on the world stage, while his maternal grandparents won European championship medals for Great Britain.

    His grandmother, Rosemary Stirling, arguably had the most impressive achievement: an 800m Commonwealth Games title from 1970.

    Despite his family pedigree, Ruthe was never under any pressure to take running seriously. His parents, in fact, didn’t allow him or his sister Daisy to train at all until they were 13, never wanting their identities to be tied solely to running.

    “It feels like it’s the right decision about now,” says Ben.

    But as he gradually starts to realize his potential, Ruthe, when pushed, admits to having big goals in the sport.

    “If I had to pick one thing, definitely Olympic gold,” he says. “I feel like that’s most runners’ dream and the biggest thing you can actually win. So that’ll definitely be the top of my bucket list.”
    The 2032 Olympics in Brisbane, Ruthe adds, would be a nice target. And as for the Los Angeles Games in three years’ time? “I’d actually love to try and qualify for LA 28,” he says. “I feel like that’ll be a tough goal. But if I do that, I’ll be really happy.”

    Already, Ruthe’s name is being mentioned in the same breath as Norway’s Jakob Ingebrigtsen, the most successful middle-distance of this generation. It was his record as the youngest-ever four-minute miler that Ruthe took last week, and the New Zealander also beat Ingebrigtsen’s 1,500m record for a 15-year-old earlier this year.

    Ingebrigtsen’s success, Ruthe says, has given him hope that he too can “have a good future” in the sport. But his biggest source of motivation comes not from the two-time Olympic champion, but from those closest to him – his training group led by coach Craig Kirkwood and athlete Sam Tanner.

    The pair were instrumental in Ruthe’s recent mile time of 3:58.35, and it was five-time national champion Tanner who paced him perfectly around four laps of the track on his way to the record.

  3. JosephFluor表示:

    посетить веб-сайт https://grunge-futbolka.ru

  4. PeterDak表示:

    Exposure to phthalates during pregnancy can affect a newborn’s brain development, study finds
    порно жесткий секс

    Phthalates — the synthetic chemicals used in everyday products for food packaging, personal care, toys and more — have been linked to abnormal neurological development in infants.

    Now, scientists may have discovered a biological pathway for how this phenomenon could occur. Researchers found that in utero exposure to phthalates is linked with altered metabolism of neurotransmitters and amino acids involved in brain maturation, according to a study published Wednesday in the journal Nature Communications.

    The report is the first to use untargeted metabolomics — the study of all small molecules or metabolites in a biological system — to connect a mother’s phthalate exposure to a newborn’s metabolites, and those metabolites to neurological development, said senior study author Dr. Donghai Liang via email.
    “This represents an important step forward in understanding how prenatal chemical exposures shape infant development at the molecular level,” added Liang, an associate professor of environmental health at Emory University’s Rollins School of Public Health in Atlanta.

    First introduced in the 1920s, phthalates are used to make plastics softer and more flexible, primarily in polyvinyl chloride (PVC) products such as vinyl flooring, medical devices, children’s toys, food packaging or shower curtains. The chemicals also help lubricate substances and carry fragrances in various personal care products including deodorant; nail polish; perfumes; hair gels, sprays or shampoos; soaps; and body lotions.

    Phthalates are also endocrine disruptors that have been linked to preterm birth, infant genital abnormalities, childhood obesity, asthma, cancer, cardiovascular issues, and low sperm count and testosterone in men.

    “We conducted this study because phthalates are everywhere in our daily lives,” Liang said, hence their nickname “everywhere chemicals.”

    Harming infant health
    The findings are based on mother-newborn pairs enrolled in the Atlanta African American Maternal-Child Cohort between 2016 and 2018. In urine samples collected from 216 mothers between eight weeks and 14 weeks of gestation at visit one and 145 participants between 24 and 30 weeks’ gestation at visit two, the authors measured eight phthalate metabolites. Participants were around age 24 on average, and their levels of some phthalate metabolites were higher than the average determined by the National Health and Nutrition Examination Survey.

    Within a day or two of birth, the authors collected the babies’ blood via a heel stick.

    The team found prenatal phthalate levels were associated with lower levels of tyrosine, an amino acid and precursor to the thyroid hormone thyroxine. Thyroxine was also abnormally low in those with in utero phthalate exposure, and low thyroxine has been previously associated with greater vulnerability to illness and neurodevelopmental issues in newborns, the authors said. Tyrosine is also a precursor to the neurotransmitters dopamine, norepinephrine and epinephrine, all of which partly contribute to the body’s fight-or-flight response. Low levels of these neurotransmitters can lead to various problems, including anxiety, depression and trouble focusing.

    Prenatal phthalate exposure was also linked with lower levels of the essential amino acid tryptophan, which converts into 5-hydroxytryptophan (or 5-HTP), which then turns into serotonin. Both 5-HTP and serotonin were also low. Serotonin has several critical roles in the body, including mood regulation, sleep, learning, memory, digestion and the body’s response to stress. Previous research has linked low serotonin with mood disorders such as depression and anxiety, sleep problems, and digestive issues.

  5. Malcolmseern表示:

    Kamagra Oral Jelly Kamagra Oral Jelly kaufen Kamagra Gel

  6. CharlesGaP表示:

    Aged 15, New Zealander Sam Ruthe has already run a four-minute mile. He would ‘love to try and qualify’ for the 2028 Olympics
    paraswap

    Sam Ruthe had the eyes of thousands on him when he stepped onto a running track in Auckland just over a week ago.

    Undaunted by the occasion, Ruthe went on to become the first 15-year-old to run a sub-four-minute mile, even managing a nonchalant shrug of the shoulders as he crossed the finish line.

    The race was almost entirely engineered for the high school student to break the fabled four-minute barrier – a feat first achieved by Roger Bannister more than 70 years ago – but the weight of running history was a burden that Ruthe seemed to bear lightly.

    The first three laps, he later said in a video documenting the race, “felt pretty comfortable – nothing too crazy.”

    Perhaps the most intimidating part of his achievement occurred when Ruthe returned to school the next day, only to be immediately called into the principal’s office.

    “He’s like, ‘Alright, so you’re gonna have to go up on stage and we’ll get the whole school to clap you,’” Ruthe tells CNN Sports’ Patrick Snell. “It was really scary, actually. I headed into class and everyone thought I was famous.”

    It’s easy to forget, given his history-making performance last week, that Ruthe is like most other 15-year-olds in New Zealand. He goes to school, spends time with his friends, and helps with chores around the house.

    He also just happens to be one of the most exciting middle-distance runners on the planet, one of the latest star athletes to emerge from sports-mad New Zealand.

  7. Derekgroum表示:

    apotek online: apotek online recept – apotek online recept

  8. Derekgroum表示:

    Kamagra Original: Kamagra Original – Kamagra Oral Jelly

  9. Joshuahaido表示:

    Recomendo o jogo a todos Tiger

  10. Pingidiof表示:

    darknet markets url https://github.com/aresonioncq0a7/aresonion – darknet markets 2025

  11. Louislen表示:

    http://apotheekmax.com/# ApotheekMax

  12. HomerFaw表示:

    https://apotheekmax.com/# de online drogist kortingscode

  13. Michaeltor表示:

    Kamagra Original: Kamagra Original – kamagra

  14. Davidmeast表示:

    другие https://xanax-futbolka.ru

  15. Derekgroum表示:

    Kamagra kaufen ohne Rezept: Kamagra kaufen – Kamagra Oral Jelly kaufen

  16. JosephFluor表示:

    Подробнее https://futbolka-alt.ru

  17. JosephFluor表示:

    кликните сюда https://xanax-futbolka.ru

  18. Michaeltor表示:

    Kamagra Original: kamagra – Kamagra kaufen

  19. Malcolmseern表示:

    Kamagra online bestellen Kamagra Oral Jelly kaufen Kamagra kaufen ohne Rezept

  20. Robertror表示:

    Look of the Week: Naomi Watts is twinning with her canine co-star
    orbiter finance
    What’s white and black and red all over? Naomi Watts and her 145lb co-star, Bing, a Great Dane, taking a dog walk on the crimson carpet for the New York premiere of “The Friend.”

    Directed by Scott Mcgehee and adapted from Sigrid Nunez’s 2018 novel of the same name, the film — set to release in US theaters on March 28 and in the UK on April 25 — follows a solitary writer and teacher named Iris whose life is upended after a close friend bequeaths his giant pet dog to her following his death.

    In front of the cameras Monday evening, the “Mulholland Drive” actor and Bing looked like they were cut from the same cloth — both in temperament and in their matching black polka dots. Watts was dressed in a white gown with fur-tufted spots that bore a striking resemblance to Bing’s own coat, but the Cruella de Vil comparisons ended there. Instead, Watts and Bing were captured in the throes of lots of paw-shakes, puppy kisses and head scratches.
    The dress that Watts wore, titled the “Domino” and designed by Jacquemus, debuted during the Spring-Summer 2025 Paris couture shows in January. The look was both elegant and offbeat, with a high-cowl neck and open-back, asymmetrical waistline that mimicked a French tuck. It was styled with a skirt that sprouted furry black polka dots, which close up were unnervingly reminiscent of body hair. But from afar they gave the impression of soft-edged dabs of watercolor bleeding downstream.

    The look was styled by Jeanann Williams, who has also been working with “The White Lotus” star Leslie Bibb. Williams’ decision to coordinate Watts with Bing was a new take on method dressing — the thematic styling trend that has dominated celebrity red carpets since Greta Gerwig’s “Barbie” in 2023. Since then, the sartorial trope, which connects actors to their on-screen characters through clothes, has become somewhat tired — with some observers claiming that the 7-month-long “Wicked” press tour, in which Cynthia Erivo and Ariana Grande became prisoners to the colors green and pink, was peak saturation.

發佈留言

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