javascript - window.print() 在 ie 中不起作用并且已经尝试了正确的修复

标签 javascript internet-explorer printing

我想在单击按钮时打印整页。我正在使用 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/

相关文章:

html - 如何在 IE9 中使用 font-face 嵌入 Lucida Sans 常规字体

pdf-generation - 大多数打印机可以处理的最小边距是多少?

javascript - 纹理是将音频数据传输到 GLSL 的唯一方法吗?

javascript - 在服务内使用 Angular $scope.info 变量

javascript - IE6 Ajax 与 JQuery

python - 我如何用 python 测量零后超过 16 位数字?

PHP MySQL : Change Cell Table Colour Based Off Database Entry

javascript - 为什么我无法使用 Jquery 显示文本

javascript - 当 src 更改时如何强制重新创建 <img/>?

java - Selenium RC 和 Internet Explorer