我使用 uiwebview 来做一个嵌入式网络应用程序,使用新的 iOS 4.2 你可以直接用 objective-C 打印,但我想从 HTML 中的 javascript 打印。
问题是在单击执行 window.print() 的按钮时我没有看到打印对话框显示。
我也写过这段代码,但它没有获取事件。
function beforePrint () {
alert("before rec");
}
function afterPrint () {
alert("after rec");
}
function checks(){
alert("Activating checks");
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
}
并且此事件是从按钮 img 启动的
onClick="js:checks();alert('print');window.print();alert('print done');"
在 Safari 中,我只收到激活支票、预览打印和“打印”、“打印完成”消息的消息……我也没有收到事件。
最佳答案
据我所知,window.print()
在 UIWebView 中运行代码时不执行任何操作。您需要编写一些 native Objective-C 来针对您的 UIWebView 运行 UIViewPrintFormatter,或者将用户发送到 Safari。
关于javascript - ios 4.2 uiwebview javascript window.print 不打印,不在事件前后启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4361119/