打印页面作为弹出窗口不工作在铬工作在Mozilla和IE浏览器 [英] printing page as popup window is not working on chrome working on mozilla and IE

查看:115
本文介绍了打印页面作为弹出窗口不工作在铬工作在Mozilla和IE浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以弹出窗口打印页面。对于Mozilla和IE而言,它的工作原理是在Chrome上弹出一个窗口,但它会导致打印预览失败。

plunker链接是


  http://plnkr.co/edit/bP9l1c0A372JYd9P6BDt?p=preview 


而javascript的部分是 -

  function PrintElem(elem){
console.log($(elem).html())

Popup($(elem).html());


函数Popup(data)
{
var printContent = data;
var disp_setting =toolbar = no,location = no,directories = no,menubar = no,scrollbars = no,width = 600,height = 800
var myWindow = window.open(, ,disp_setting);
myWindow.document.write(printContent);

myWindow.document.close();
myWindow.focus();
myWindow.print();
myWindow.close();
返回true;
}

不知道Chrome为何不满意我的脚本。

$如果您使用的是JQuery,您可以使用 $(document).ready(function(){});
解决方案

/ code>。看看这里:

  $(function(){
window.print();
window.close();
});


I am trying to print a page as popup window. For Mozilla and IE its working but on chrome a popup window appears but it gives "print preview failed".

The plunker link is

http://plnkr.co/edit/bP9l1c0A372JYd9P6BDt?p=preview

And portion of javascript is -

function PrintElem(elem) {
    console.log($(elem).html())

     Popup($( elem).html());
}

function Popup(data)
{
    var printContent = data;
    var disp_setting="toolbar=no,location=no,directories=no,menubar=no, scrollbars=no,width=600, height=800"
    var myWindow = window.open("","",disp_setting);
    myWindow.document.write(printContent);

    myWindow.document.close();
    myWindow.focus();
    myWindow.print();
    myWindow.close();
    return true;
}

Not sure why Chrome is not happy with my script.

解决方案

If you are using JQuery, you can use $(document).ready(function () {});. Have a look at this here:

$(function () {
  window.print();
  window.close();
});

这篇关于打印页面作为弹出窗口不工作在铬工作在Mozilla和IE浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆