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

A detailed introduction to the CSS naming specification BEM from QQtabBar

BEM from QQtabBar First of all, what does BEM mea...

What to do if you forget your password in MySQL 5.7.17

1. Add skip-grant-tables to the my.ini file and r...

Install Apple Mac OS X in VMWare12 Graphic Tutorial

1. Introduction: Because my friend wanted to lear...

Writing a rock-paper-scissors game in JavaScript

This article shares the specific code for writing...

Summary of seven sorting algorithms implemented in JavaScript (recommended!)

Table of contents Preface Bubble Sort Basic Algor...

How to embed flash video format (flv, swf) files in html files

Flash file formats: .FLV and .SWF There are two ex...

MySQL data insertion optimization method concurrent_insert

When a thread executes a DELAYED statement for a ...

MySQL learning notes: data engine

View the engines supported by the current databas...

Are the value ranges of int(3) and int(10) the same in mysql

Table of contents Question: answer: Reality: Know...

js array fill() filling method

Table of contents 1. fill() syntax 2. Use of fill...

Complete step record of vue encapsulation TabBar component

Table of contents Implementation ideas: Step 1: C...

Multiple methods to modify MySQL root password (recommended)

Method 1: Use the SET PASSWORD command MySQL -u r...

Singleton design pattern in JavaScript

Table of contents 1. What is a design pattern? 2....