About the solution record of the page unresponsiveness when using window.print() in React

About the solution record of the page unresponsiveness when using window.print() in React

1. Background of the problem:

window.print()頁面打印出現頁面無響應

I have seen many solutions online that use window.location.reload() . I am not sure about this solution. Refreshing the page can certainly solve this problem, but it is not advanced.

2. Causes of the problem:

The document may have been manipulated but not destroyed (maybe)

3. Problem solving:

Eliminate the document of the operation

封裝一個printFun()方法

//The method parameter content: the element to be printed printFun = (content) => {
        var Window = window.open("", "Print Page", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no");
        var style = "<style type='text/css'></style>";
        Window.document.write(content + style);
        Window.focus();
        Window.document.close(); //Close the output stream of the document and display the selected data Window.print(); //Print the current window return Window;
    }

Method call: billDetails是你當前想要打印的元素的id,當然只要是能找到該元素,其他方法都可以

var windows = this.print(document.getElementById('billDetails').innerHTML);
    windows.close();

Summarize:

If there are style problems, you need to add CSS to the code yourself, that is, style variable in the printFun method, and you need to change it yourself

This is the end of this article about how to solve the problem of page unresponsiveness when using window.print() in React. For more related content about page unresponsiveness when using window.print() in React, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  CSS Tutorial: CSS Attribute Media Type

>>:  Nginx implements high availability cluster construction (Keepalived+Haproxy+Nginx)

Recommend

Solution to CSS flex-basis text overflow problem

The insignificant flex-basis has caused a lot of ...

Vue implements a scroll bar style

At first, I wanted to modify the browser scroll b...

How to use type enhancement without typingscript

Preface Due to the weak typing of JS, loose writi...

Docker connects to the host Mysql operation

Today, the company project needs to configure doc...

Example code for implementing a text marquee with CSS3

Background Here's what happened, Luzhu accide...

The difference between html, xhtml and xml

Development Trends: html (Hypertext Markup Languag...

How to use ElementUI pagination component Pagination in Vue

The use of ElementUI paging component Pagination ...

Detailed explanation of Linux mpstat command usage

1. mpstat command 1.1 Command Format mpstat [ -A ...

MySQL grouping queries and aggregate functions

Overview I believe we often encounter such scenar...

How to implement Linux deepin to delete redundant kernels

The previous article wrote about how to manually ...

Example of Vue uploading files using formData format type

In Vue, we generally have front-end and back-end ...

Webpack loads css files and its configuration method

webpack loads css files and its configuration Aft...

Teach you MySQL query optimization analysis tutorial step by step

Preface MySQL is a relational database with stron...

Mysql sql slow query monitoring script code example

1. Modify my.cnf #The overall effect is that both...