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

MySQL full backup and quick recovery methods

A simple MySQL full backup script that backs up t...

How to deploy code-server using docker

Pull the image # docker pull codercom/code-server...

Ubuntu16.04 builds php5.6 web server environment

Ubuntu 16.04 installs the PHP7.0 environment by d...

Vue implements book management case

This article example shares the specific code of ...

Sample code on how to implement page caching in vue mobile project

background On mobile devices, caching between pag...

Vue resets data to its initial state

In some cases, the data in data needs to be reuse...

Vue implements three-dimensional column chart based on echarts

The three-dimensional column chart consists of th...

Shell script settings to prevent brute force ssh

The shell script sets access control, and the IP ...

React+Antd implements an example of adding, deleting and modifying tables

Table of contents Table/index.js Table/model/inde...

How to use vw+rem for mobile layout

Are you still using rem flexible layout? Does it ...

Native js to achieve star twinkling effect

This article example shares the specific code of ...

mysql8.0.11 winx64 installation and configuration tutorial

The installation tutorial of mysql 8.0.11 winx64 ...

jQuery plugin to implement floating menu

Learn a jQuery plugin every day - floating menu, ...