问题描述
我有一个Angular2 +/Cordova应用程序,我正在提出API请求以获取PDF.我想在Web +本机环境中打开此PDF.
I have an Angular2+/Cordova app, and I'm making an API request to get a PDF. I'd like to open this PDF in Web + Native environments.
对于网络,我正在打开窗口,获取PDF&从中创建一个Blob,然后执行createObjectURL
并将窗口的location.href
设置为该URL.效果很好(在Chrome/FF上).
For web I'm opening the window, getting the PDF & creating a Blob from it, then doing createObjectURL
and setting the window's location.href
to that URL. It works well (on Chrome/FF).
在本机上,我想做类似的事情,但理想情况下,只需使用来自createObjectURL
的URL进行window.open(通过InAppBrowser
插件).这可能吗?我返回的URL类似于:blob:file:///ef76ad0d-7c7f-4817-915f-9097160d1a58
.尝试通过具有_system
目标的InAppBrowser打开此文件绝对不会执行任何操作.没有错误,没有窗口,什么也没有.想知道是否需要为此做特别的白名单或SCP事情?
On native I'd like to do something similar, but ideally just do a window.open (via the InAppBrowser
plugin) with the URL that came from createObjectURL
. Is this possible? The URL I get back is something like: blob:file:///ef76ad0d-7c7f-4817-915f-9097160d1a58
. Trying to open this via InAppBrowser with a _system
target does absolutely nothing. No errors, no windows, no nothing. Wondering if there are special whitelist or SCP things I need to do for this?
推荐答案
作为参考,我不喜欢这种解决方案,但是在这种情况下,我最终以不同的方式对待web和native.
For reference, I don't like this solution, but I ended up treating web and native differently in this case.
WEB:打开窗口-> REST调用以获取Blob->带Blob的createObjectURL->将窗口位置href设置为上一步的结果
WEB:Open Window --> REST call to get Blob --> createObjectURL with Blob --> set window location href to result of previous step
本机:REST调用以获取Blob->使用Cordova File插件保存Blob->使用Cordova File Opener插件打开保存的文件
NATIVE:REST call to get Blob --> Save Blob with Cordova File plugin --> Open saved file with Cordova File Opener plugin
这篇关于在Cordova InAppBrowser上打开createObjectURL Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!