Get the App
SLTechnology News&Howtos  ›  Development  › 

What if there is a problem of page unresponse when using window.print () in React?

Shulou Source: shulou.com Published: 2022-06-02 15:34:56 09月23日 Update

This article mainly introduces the React in the use of window.print () page unresponsive problem how to do, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.

1. Background of the question:

The window.print () page prints and the page does not respond.

Many methods on the Internet are to let _ window.location.reload (), for this solution is non-committal, refresh the page can of course solve this problem, but not advanced

Second, the cause of the problem:

Document may have been operated but not destroyed (possibly)

3. Problem solving:

Eliminate the document of the operation

Encapsulate a printFun () method

/ / the method parameter content: elements to be printed: printFun = (content) = > {var Window = window.open ("", "Page print", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no"); var style = ""; window. [XSS _ clean] (content + style); Window.focus (); Window.document.close () / / close the output stream of document and display the selected data Window.print (); / / print the current window return Window;}

Method call: billDetails is the id of the element you currently want to print. Of course, as long as the element can be found, other methods can.

Var windows = this.print (document.getElementById ('billDetails') [xss_clean]); windows.close (); Thank you for reading this article carefully. I hope the article "what to do if the page does not respond when using window.print () in React" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Questions pages methods articles elements what to do advanced non-committal values interests methods reasons parameters at the same time data solutions more friends knowledge editing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn Xiaomi macOS MySQL