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

17,277 Responses

  1. BrettTIT表示:

    order ed meds online: cheap cialis – erectile dysfunction meds online

  2. BrettTIT表示:

    buy Viagra online: buy viagra online – Cheap generic Viagra

  3. неотложная наркологическая помощь в москве неотложная наркологическая помощь в москве .

  4. Diplomi_exml表示:

    где купить диплом сайты 2orik-diploms.ru .

  5. срочное оформление загранпаспорта срочное оформление загранпаспорта .

  6. сколько стоит сделать загранпаспорт сколько стоит сделать загранпаспорт .

  7. срочное оформление загранпаспорта срочное оформление загранпаспорта .

  8. срочное оформление загранпаспорта срочное оформление загранпаспорта .

  9. Charlesbot表示:

    http://maxpillsformen.com/# Cheap Cialis

  10. Donaldabula表示:

    Cheapest Sildenafil online FastPillsForMen buy viagra here

  11. BrettTIT表示:

    Viagra online price: FastPillsForMen.com – Viagra without a doctor prescription Canada

  12. Barrybib表示:

    Generic Tadalafil 20mg price: Max Pills For Men – Buy Tadalafil 10mg

  13. LarryNem表示:

    Desyn Protocol
    The Desyn Protocol: An Overview
    The Desyn Protocol is a cutting-edge framework designed to enhance blockchain technology by offering a scalable and more secure ecosystem. As the demand for decentralized applications grows, the need for efficient protocols becomes crucial. Desyn addresses these needs with a unique approach, providing developers and organizations with the tools to build and manage decentralized systems with enhanced capabilities.
    desyn
    Core Features of Desyn Protocol
    Scalability: The protocol integrates advanced scalability solutions, allowing for increased transaction throughput and reduced latency.
    Security: By utilizing state-of-the-art cryptography, Desyn ensures that transactional integrity and data protection are maintained.
    Flexibility: Desyn’s modular architecture enables seamless adaptability to various use cases in the blockchain sector.
    Applications and Benefits
    The Desyn Protocol is versatile, finding applications across different sectors that require blockchain solutions. In finance, it aids in creating smart contracts that bring efficiency and transparency to financial transactions. In supply chain management, Desyn can enhance traceability and accountability from production to distribution. The healthcare industry benefits from secure, immutable record keeping, ensuring both data integrity and patient privacy.

    With its emphasis on scalability and security, Desyn reduces resource consumption while optimizing performance, thus driving down operational costs. The flexibility of its architecture supports rapid deployment and integration with existing systems, providing a strategic advantage to businesses looking to transform digitally.

    Moreover, developers benefit from the open-source nature of the protocol, which encourages community involvement and continuous innovation. Desyn’s approach promises to lower barriers to entry for startups and established companies alike, fostering a vibrant ecosystem of development.

    Conclusion
    In conclusion, the Desyn Protocol represents a significant advancement in blockchain technology by combining scalability, security, and flexibility. Its wide range of applications and benefits make it a preferred choice for various industries seeking to leverage blockchain’s transformative power. As the landscape of decentralized technology evolves, Desyn is poised to play a pivotal role, offering solutions that are innovative, efficient, and secure. The protocol’s commitment to enhancing user experience and enabling strategic growth makes it a valuable asset in the digital transformation journey.

  14. Danielglync表示:

    Welcome to Vertex Protocol: Revolutionizing DeFi Trading
    Discover the revolutionary Vertex Protocol, your gateway to the world of decentralized finance (DeFi) trading. As the crypto landscape rapidly evolves, Vertex Protocol stands at the forefront, providing users with unparalleled seamless trading experiences and enhanced liquidity access.
    vertex protocol staking
    What Makes Vertex Protocol Stand Out?
    Vertex Protocol is more than just a trading platform. It is a designed to empower you with:

    Intuitive User Interface: Navigate the complex world of crypto with ease and efficiency.
    Advanced Security: Enjoy peace of mind with industry-leading security protocols and safeguarding of your assets.
    High Liquidity: Access deep liquidity pools to execute large trades with minimal slippage.
    Diverse Asset Options: Explore a wide array of cryptocurrencies and tokens.
    Unlock Potential with Vertex’s Features
    Leverage the full potential of Vertex Protocol with these standout features:

    Decentralized: Trustless and Secure
    Trading on Vertex ensures transparency and autonomy, free from third-party control, making it a trustless and secure choice for crypto enthusiasts.

    Efficient Trading Engine
    Benefit from fast, efficient trade execution supported by state-of-the-art technology that maximizes your trading efficiency.

    Community Governance
    Be a part of a community-driven , allowing you to have a say in the protocol’s future developments.

    Getting Started with Vertex Protocol
    Embarking on your DeFi journey with Vertex is straightforward. To get started:

    Sign up and create your account.
    Securely connect your wallet.
    Begin trading and explore diverse assets and liquidity options.
    Whether you are a seasoned trader or new to the crypto scene, Vertex Protocol offers the tools and resources you need to succeed.

    Join the Vertex Community
    Participate in webinars, discussions, and forums to stay informed and connected. The vibrant awaits, offering support and insights to enhance your trading journey.

    In conclusion, Vertex Protocol is your ideal partner in navigating the dynamic world of decentralized finance. Start today and experience the future of trading.

  15. Jameshic表示:

    Ethena Fi – Your platform for decentralized financial services
    [url=https://eithena.fi]ethena[/url]
    Invest, exchange, and manage your assets with confidence on Ethena Fi
    Discover the power of decentralized finance with Ethena Fi. As the world moves towards decentralized financial solutions, Ethena Fi offers you a platform to explore the limitless possibilities of cryptocurrency investments, exchanges, and asset management.

    At Ethena Fi, we believe in empowering individuals to take control of their financial future. Whether you’re an experienced investor or new to the world of cryptocurrencies, our user-friendly platform provides you with the tools and resources you need to succeed.

    With Ethena Fi, you can:

    Invest in a wide range of cryptocurrencies, including Bitcoin, Ethereum, and more
    Exchange digital assets quickly and securely
    Manage your portfolio with ease
    Access innovative financial products and services
    Join thousands of users who have already started their journey to financial freedom with Ethena Fi. Sign up today and experience the future of decentralized finance!

  16. наркологическая скорая помощь москва http://www.klin.0pk.me/viewtopic.php?id=4428 .

  17. как вызвать наркологическую скорую помощь в москве как вызвать наркологическую скорую помощь в москве .

  18. hgmakeup.com表示:

    Of course, what a great site and informative posts, I will add backlink – bookmark this site? Regards, Reader

  19. RogerFaf表示:

    http://fastpillseasy.com/# buying erectile dysfunction pills online

  20. RogerFaf表示:

    https://maxpillsformen.com/# Generic Cialis price

  21. VincentRop表示:

    Welcome to DeFiLlama: The DeFi Data Powerhouse
    In the ever-evolving world of decentralized finance, staying informed is crucial. DeFiLlama stands out as a comprehensive platform offering in-depth analytics and insights into the DeFi ecosystem. Whether you’re a seasoned investor or new to DeFi, DeFiLlama provides the tools and data you need to make informed decisions.
    defillama app
    Why Choose DeFiLlama?
    DeFiLlama excels in delivering unbiased, reliable data that the crypto community can trust. Here’s why it’s a favorite among DeFi enthusiasts:

    Complete Transparency: DeFiLlama offers an open data approach, ensuring transparency and accuracy in all metrics provided.
    Extensive Coverage: With data on a wide array of DeFi protocols, it provides the most comprehensive DeFi analytics available.
    User-Friendly Interface: Navigate easily through DeFiLlama’s clear layout and access the data you need quickly.
    Regular Updates: Stay current with frequent updates, delivering the latest DeFi data.
    Explore Key Features
    Total Value Locked (TVL): One of the most important metrics in the DeFi space, TVL indicates the amount of assets locked in DeFi protocols. DeFiLlama tracks TVL across multiple chains, providing a comprehensive view of where value is being generated.

    Protocol Rankings: Discover which DeFi protocols are leading the pack. DeFiLlama’s rankings help you track the top-performing projects across various chains.

    Chain Analysis: Beyond individual protocols, DeFiLlama offers insights into how different blockchain networks compare in terms of ecosystem growth and performance.

    Community and Collaboration
    DeFiLlama believes in the power of community feedback and collaboration. They continuously improve their offerings based on community input, ensuring the platform meets the evolving needs of its users.

    Join the growing community of DeFi enthusiasts who trust DeFiLlama for their data needs.

    Start Your DeFi Journey Today
    Whether you’re new to DeFi or looking to deepen your understanding, DeFiLlama is your go-to resource for data that helps drive decisions. Dive into the world of decentralized finance with all the information you need at your fingertips.

    Visit today and explore the future of finance!

  22. Mathewnus表示:

    Introducing the Zircuit Token System
    The Zircuit token, a pivotal element in the blockchain landscape, plays a crucial role in enabling efficient transactions and offering enhanced security. Designed for seamless integration into various platforms, it aims to revolutionize the way digital currencies are perceived and utilized.
    zircuit bridge
    Key Advantages of the Zircuit Token
    Enhanced Security: Security is a core benefit of utilizing the Zircuit token. By employing advanced cryptographic techniques, it ensures that transactions are secure, safeguarding user data and funds from potential threats.
    Scalable Transactions: Zircuit token is engineered for scalability, allowing for a large number of transactions per second. This capability promises efficiency even as user numbers grow, ensuring smooth operations across digital platforms.
    Low Transaction Fees: One of the significant advantages of using the Zircuit token is the cost-effectiveness of its transactions. It boasts lower fees compared to traditional financial systems, making it an attractive option for users.
    Implementing Zircuit Tokens in Everyday Use
    The implementation of Zircuit tokens into daily transactions is designed to be straightforward. Users can manage their tokens seamlessly through dedicated wallets that offer user-friendly interfaces and robust security. Thanks to its decentralized nature, it enables trustless interactions, where intermediaries are reduced, thereby minimizing costs and enhancing speed.

    Furthermore, Zircuit tokens offer compatibility with various platforms, allowing users to transact with ease across a plethora of services. This flexibility is crucial for both individuals and businesses looking to integrate blockchain technology into their operations.

    In conclusion, the Zircuit token stands as a testament to the evolving nature of digital currencies, offering a secure, scalable, and cost-effective solution for modern financial transactions. As adoption continues to grow, the robustness of the Zircuit token system is likely to play a critical role in shaping the future of digital exchanges.

發佈留言

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