Page unresponsive problem resolution record with window. print of in React
- 2021-12-05 05:12:43
- OfStack
Catalogue 1. Problem background: 2. Problem cause: 3. Problem solution: Summary:
1. Background of the issue:
window.print()页面打印出现页面无响应
After reading the Internet, many methods are used
window.location.reload()
Of course, refreshing the page can solve this problem, but it is not advanced
2. Causes of the problem:
document may have been operated but not destroyed (it may be)
3. Problem solving:
document of elimination operation
封装1个printFun()方法
// The method parameter content Elements to Print
printFun = (content) =>{
var Window = window.open("", " Page printing ", "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(); // Shut down document Output stream of , Display selected data
Window.print(); // Print the current window
return Window;
}
Method invocation:
billDetails是你当前想要打印的元素的 id,当然只要是能找到该元素,其他方法都可以
var windows = this.print(document.getElementById('billDetails').innerHTML);
windows.close();
Summary:
If there is a style problem, you need to add css to your code, that is,
printFun
Method in thestyle
Variable, you need to make your own requirements changes