2012-10-31 127 views
0

在javascript中下面的代碼不會顯示實際的打印對話框。新窗口打開好但沒有打印對話框。 IE/Chrome/Mozilla瀏覽器都很好。 我已經閱讀了所有與opera有關的常見超時問題,並試過我相信解決方案的所有可能性。asp.net opera打印對話框

任何人都知道解決方案是什麼?

var windowUrl = 'about:blank'; 
var UserLoggedIn = $("#lblUser").text() 
var now = new Date(); 
var strDateTime = [ 
    [AddZero(now.getDate()), AddZero(now.getMonth() + 1), now.getFullYear()].join("/"), [AddZero(now.getHours()), AddZero(now.getMinutes())].join(":"), now.getHours() >= 12 ? "PM" : "AM"].join(" "); 
var Database = 'ProductionDatabase'; 
var windowName = 'Report'; 
var AuditPrintDetailEverypage = UserLoggedIn + ' Time : ' + strDateTime; 
var AuditPrintDetailLastPage = '  Report ' + ' Source Database: '; 
var WinPrint = window.open(windowUrl, windowName, 'left=300,top=300,right=500,bottom=500,width=1000,height=500,scrollbars=1'); 
WinPrint.document.write('<' + 'html' + '><head><link href="assets/css/Print.css" rel="stylesheet" type="text/css" /><title>' + AuditPrintDetailEverypage + '</title> </head><' + 'body style="background:none !important"' + '>'); 
WinPrint.document.write(printContent.innerHTML); 
WinPrint.document.write('   ' + AuditPrintDetailLastPage); 
WinPrint.document.write('<' + '/body' + '><' + '/html' + '>'); 
WinPrint.document.close(); 

if (window.opera) { 
    window.onload = function() { 
     window.setTimeout(function() { 
      window.print; 
     }, 500); 
    } 
} else { 
    WinPrint.focus(); 
    WinPrint.print(); 
    WinPrint.close(); 
} 
+4

Isnt'window.print'方法嗎?你不應該調用'window.print()'嗎? – Tejs

+2

而且你還設置'window'的'onload',而不是'WinPrint'。你不想在該代碼區使用'WinPrint'來處理所有出現的'window'? (保留'if(window.opera)'雖然,那很好) – Ian

+2

'about:blank'並不是一個真正的跨瀏覽器解決方案(f.ex. opera內部重定向到'opera:blank') - 使用'javascript :void(0)'代替。 – pozs

回答

0

看起來像()對歌劇來說很重要,與一些網站相反。 希望這可以幫助別人。向上面的人回信。

    if (window.opera) { 


         WinPrint.onload = function() { 
          WinPrint.setTimeout(function() { 
           WinPrint.print(); 
          }, 500); 
         }