问题
I want to use WL.App.OpenURL('http://localhost:8080/AbcProj/apps/myApp/common/test.pdf','_blank'); despite this file exists at said path
its raising error http error 404
problem accessing /AbcProj/apps/myApp/common/test.pdf
回答1:
This is not really possible using the WL API (or PhoneGap/Cordova for that matter). It is just not designed for that. See https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14855386�.
One possible solution is to use ChildBrowser, which is a Cordova plugin, to open it using a native WebView. See Open pdf using phone gap.
The issue with ChildBrowser is that you will need to implement it in each platform you deploy ie. Android, iOS, etc.
Another possible solution is to just let the platform open the PDF with the native viewer. For example, if you open a PDF in GMail in Android, it will kick you out to the PDF viewer in Android. That should be implemented by just having an external link to the PDF. Once a user clicks it, WL will kick them out to native browser.
回答2:
I have used OpenURL and it works fine to me.
WL.App.OpenURL('http://localhost:8080/AbcProj/apps/myApp/common/test.pdf','_blank');
回答3:
Check out module 16 and its sample. It might be what you're looking for. http://pic.dhe.ibm.com/infocenter/wrklight/v5r0m5/index.jsp?topic=%2Fcom.ibm.worklight.help.doc%2Fstart%2Fc_gettingstarted.html
回答4:
You can try:
window.open("test.pdf","_blank","location=no");
And use relative paths.
On worklight 5.0.6 (and phonegap) this should work, if using phonegap include the cordova.js or else the "close" button on the new window won't appear (as it will use the window.open of the native web view, on worklight the build process should include the required .js to make window.open behave as expected).
http://docs.phonegap.com/en/2.7.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser
来源:https://stackoverflow.com/questions/14444333/ibm-worklight-app-common-pdf-file-access