我想在单击按钮时打印整页。我正在使用 window.print() 但它不适用于 ie。我用谷歌搜索了一个解决方案,但没有任何帮助。也许有人知道我做错了什么。
我的代码:
$('#PrintTool').click(function () {
var printVal = document.documentElement.innerHTML;
var newWin = window.open();
newWin.document.write(printVal);
newWin.document.close();
newWin.focus();
newWin.print();
newWin.close();
});
希望你能帮助我
最佳答案
结账:window.print() not working in IE
工作示例:http://jsfiddle.net/Q5Xc9/1/
<html>
<head>
<script type="text/javascript">
function openWin()
{
var myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>This is 'myWindow'</p>");
myWindow.document.close();
myWindow.focus();
myWindow.print();
myWindow.close();
}
</script>
</head>
<body>
<input type="button" value="Open window" onclick="openWin()" />
</body>
</html>
关于javascript - window.print() 在 ie 中不起作用并且已经尝试了正确的修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31934447/