[英]How to print multiple files with js and asp.net
我不得不運行一些服務器端代碼,以通過javascript打開多個文件,達到了這種效果:
假設r只是一些數據的閱讀器:
If r IsNot Nothing Then
Dim sb As New StringBuilder()
Do While r.Read()
'added below to replace \\ with http://
strURL = Replace(CType(r("AttachmentLink"), String), "\\myServer\MyFolder\MyPath", "http://MyFolder/MyPath", , , CompareMethod.Text)
'added below to replace \ with /
strURL = Replace(strURL, "\", "/")
sb.AppendLine("window.open('" & strURL & "', '_blank', 'menubar=no');")
Loop
ClientScript.RegisterStartupScript(Me.GetType(), "popup", sb.ToString(), True)
End If
這對於打開多個附件非常有用...但是現在我不僅需要打開它們,還要打印它們...
因此,我嘗試着采用上面的內容並進行一些修改:
Do While r.Read()
'added below to replace \\ with http://
strURL = Replace(CType(r("AttachmentLink"), String), "\\myServer\MyFolder\MyPath", "http://MyFolder/MyPath", , , CompareMethod.Text)
'added below to replace \ with /
strURL = Replace(strURL, "\", "/")
sb.AppendLine("var oWindow = window.open('" & strURL & "', '_blank', 'menubar=no');")
sb.AppendLine("oWindow.print();")
sb.AppendLine("oWindow.close();")
Loop
ClientScript.RegisterStartupScript(Me.GetType(), "popup", sb.ToString(), True)
這當然是行不通的,沒有錯誤,但沒有任何反應。 我希望打開每個窗口,並彈出一個使用javascript的打印對話框...
有任何想法嗎?
由於瀏覽器JavaScript安全性原因,不允許您打印子窗口。
您可以做的是將加載腳本添加到要打印的頁面中,這些腳本將從該子窗口開始打印。
在某種意義上, 檢查此答案顯示出一些不同的方式:
iframe
onload
事件進行打印...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.