使用jquery打印图像不起作用

Print Image with jquery dont work

本文关键字:不起作用 图像 打印 jquery 使用      更新时间:2023-09-26

Hy Guys。。。

我有一些lightbox脚本,可以在其中构建自定义按钮。我做了一个按钮来打印灯箱中显示的图像。。但图像没有出现在打印窗口上(在谷歌Chrome、Firefox和IE8中测试)。。。这是我的

我的代码:

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#getdropdown").change(function() {
        var trial=jQuery("#getdropdown option:selected").val();
        
        jQuery.lightbox(trial,{
              buttons: [
                {
                  'class'     : 'botao-imprimir',
                  'html'      : 'IMPRIMIR',
                  'callback'  : function(url) {
                    title = window.open(trial);
                    //title.document.write(trial);
                    title.print();
                  }
                }
              ]
            });     
        
    });
});
</script>

这是我的HTML:

<select name="getdropdown" class="drop-receitas" id="getdropdown">
    <option value="">Escolha aqui a receita desejada</option>
    <option value="receitas/image.jpg">Image</option>
    <option value="receitas/image2.jpg">Image 2</option>    
</select>

var trial上,我有图像,当我在列表中选择某个选项时,它会显示带有按钮"的图像;IMPRIMIR";(打印)。。我做错了什么?

泰寻求帮助!

编辑:这是问题的链接。点击DropDown 上的某些项目

您应该打开一个HTML页面的窗口对象,该页面包含标签中的图像。类似这样的东西:

jQuery.lightbox(trial, {
  buttons: [
    {
      'class'     : 'botao-imprimir',
      'html'      : 'IMPRIMIR',
      'callback'  : function(url) {
        var imgWindow = window.open('', 'popup', 'toolbar=no,menubar=no,width=imageWidth,height=imageheight');
        imgWindow.document.open();
        imgWindow.document.write("<html><head></head><body onload='window.print()'><img src='"+url+"' /></body></html>");
        imgWindow.document.close();
       }
     }
   ]
 });

另一种方法是使用打印样式表,它隐藏除图像之外的所有其他内容。看看这里:http://www.webcredible.co.uk/user-friendly-resources/css/print-stylesheet.shtml(谷歌第一次点击)。