2012-03-02 47 views
0

Hy Guys ...打印圖像與jquery不工作

我有一些燈箱腳本,我可以建立自定義按鈕。我maked一個BUTTOM打印圖像顯示在燈箱..但圖像不apear打印窗口(在谷歌Chrome,火狐的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打印」(打印)圖像..我做錯了什麼?

求助!編輯:Here是與問題的鏈接。點擊DropDown上的某個項目

+0

我檢查了我的chrom 15.0,圖像完全出現了 – sandeep 2012-03-02 12:44:04

+0

圖像是否被設置爲背景圖像?默認情況下會打印它們,但瀏覽器中有一個選項可用於啓用它。 – Jon 2012-03-02 12:44:52

+0

@Jon - no ..圖像未設置爲背景....圖像是下拉列表的選項值:'' @sandeep - 我的Chrome版本是17.0 - 但我已經在Firefox和IE 8中測試過,並且我無法打印圖像。你可以嗎? – Preston 2012-03-02 12:48:44

回答

0

您應該打開一個窗口對象到一個包含標籤中圖像的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(); 
     } 
    } 
    ] 
}); 

做它使用的打印樣式表,隱藏everyting別的,比形象的另一種方式。看看這裏:http://www.webcredible.co.uk/user-friendly-resources/css/print-stylesheet.shtml(首次谷歌命中)。

+0

謝謝..現在在所有瀏覽器中工作!我不知道我需要打開整個HTML。我只用圖片標籤進行測試,效果很棒! – Preston 2012-03-02 13:14:42