我必须运行一些服务器端代码才能通过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弹出一个打印对话框......
有什么想法吗?
答案 0 :(得分:0)
由于浏览器javascript安全原因,您不能打印子窗口。
您可以做的是将加载脚本添加到您要打印的页面中,这些页面将从该子窗口启动打印。
Check this answer在某种意义上显示了一点点不同的方法:
iframe
onload
事件以打印它......