I am having issue with InAppBrowser on Android,it is not loading/displaying pdf file.
var ref = window.open('http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf', '_blank', 'location=yes');
I tried with _system,it is downloading the file.But I want it as just display without download. I found the same questions in Stackoverflow but didnt find the exact answer as per my requirement.Any help would be appreciated.
Try This..
var ref = window.open("https://docs.google.com/gview?embedded=true&url=http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf", '_blank', 'location=yes');
Becuse Andoid Webkit has not power to Directly open pdf as IOS.. So open with google Doc.
Related
Following scenario:
I am using the InAppBrowser plugin from Ionic Native and I am navigating to a local html.. I open the first html in the InAppBrowser with the code:
this.inappbrowser.create("files/index.htm");
The index.htm contains links to some pdf documents. Its a known issue that the InAppBrowser can't display/open a pdf file on an Android device. How can I tell the InAppBrowser to open documents with the Document Viewer from Ionic Native or something else that can display it? Or is there a way to subscribe to an event and catch the url if I click on an link to a pdf?
Thanks!
You can't directly open PDF in external App. You can try this solution.
Coming here, desperately, I really need help with an answer for my question... I do have a inAppBrowser and my can't ready a PDF (after accessing pdf view). I use cordova, phonegap. I know that I can't read a PDF because for android IAB didn't implemented a viewer, but, how can i use plugin FileTransfer? or open(url, _system). From the start, I call my app as open(url, _blank). If I'm pressing on PDF link, want my IAB to be transformed in _system, but when I go back, want my app still be _blank. Or, if I'm accessing a PDF link, to be downloaded, using FileTransfer. I had tried this 2 codes:
FileTransfer:
var fileTransfer = new FileTransfer();
fileTransfer.download(url, "");
If I'm accessing PDF link, nothing happens...
And _system:
cordova.InAppBrowser.open(url, '_system', 'location=no');
This code works fine, but! After I'm accessing PDF link, IAB -> transforms into _system, but when I go back and I press on PDF link again, nothing happens anymore... (so what I want is my IAB, to be _blank again)
Thank you !
I am working in cross platform using phonegap. When i tried Download Phonegap API in IOS, file is getting downloaded in phone rather in SD Card So its not safe to save it phone,so Please Suggest me solution So that it support both Android and ios to open file to view without downloading.....
Thanks in Advance
For Android:
You can use FileOpener plugin to do the same. This plugin will help you to open all the files store in your asset folder in android and resource folder in iOS. As well as you can open global image as well.
Have a look on this github page you will able to find the plugin.
You no need to download any content.
And For iOS you can use only:
function openFile(url) {
window.open(url, '_blank');
}
You can get file link from server and open in InAppBrowser
var ref = window.open(your_url, 'random_string', 'location=no');
ref.addEventListener('loadstart', function(event) {
});
ref.addEventListener('loadstop', function(event) {
console.log(event.type + ' - ' + event.url);
});
ref.addEventListener('exit', function(event) {
});
Have anyone used Childbrowsers or InAppBrowser plugin for pdf/anydoc viewer in android...IF so how does it work..I need to develop a document viewer for my phonegap Application...Plz suggest something..Thanks :)
Please look at the provided documentation or tells us what you have tried
InAppBrowser is a built in plug-in for the standard phonegap release since version 2.3.0.
Childbrowser was used for version previous to that as a non default plug-in.
Documentation is on the phonegap website
http://docs.phonegap.com/en/2.5.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser
Andrdoid does not come with a default PDF viewer. So you may need to open your docs using google document reader and display in your InAppBrowser.
For everybody who is stuck with this problem here is what i´ve finally found out:
HTML 5 object tag: not working
Embedded tag: not working
childBrowser Plugin: I think it would work, but it is designed for the 2.0.0 version. So you´ll get a lot of errors so i didn´t get it to work.
Phonegap InAppViewer: If you use it like that:
window.open('http://www.example.com/test.pdf', '_blank', 'location=yes')
it wont work. The InAppViewer can´t open PDF, it doesn´t matter if the PDF is external or local stored.
My solutions so far (not what the actual idea was):
you can call the window function with _system. like that:
window.open('http://www.example.com/test.pdf', '_system', 'location=yes')
this will open the PDF in the normal Browser and download it. After downloading it will ask if it should open it with a PDF viewer. But you have to go back to your app and open it again after that.
Another possibility would be that you just download it to your sdcard with the Phonegap Filesystem API like that:
var fileTransfer = new FileTransfer();
fileTransfer.download(
"http://developer.android.com/assets/images/home/ics-android.png",
"file://sdcard/ics-android.png",
function(entry) {
alert("download complete: " + entry.fullPath);
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
});
The last thing i´ve found out is, to use Google docs/drive to open it with the InAppViewer linked to google docs like that:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.open('https://docs.google.com/viewer?url=http://www.example.com/test.pdf&embedded=true', '_blank', 'location=yes');
ref = window.open('index.html', '_self');
}
This will open the PDF in the app viewing it on google docs. You can generate your permalink here: https://docs.google.com/viewer So even if you change your pdf file, it will still work
I hope this summary will help you save time. If there is another solution let me know
I am working on a project with PhoneGap and JqueryMobile in Android.
Now I need to open an external link via the Android Browser.
I just write
window.location.href("http://stackoverflow.com")
or
window.open("http://stackoverflow.com")
The App didn't reply at all?
Please tell me why and help me out. Thanks.
You need to use navigator.app.loadUrl('http://stackoverflow.com');
EDIT
Some code for PhoneGap always needs to be device-specific. What I do rather than device check is load a "platform" JS file which has code for each feature that has platform-specific code.
So you can create a function called openUrl which you define in each (Android, iOS, etc) project. In your index.html you just load the platform.js file using a relative path.
The implementation can then be platform-specific without ugly device checking.
Comment in phonegap config "res/xml/config.xml"
<access origin=".*" browserOnly="true"/>
by
<!--<access origin="*" browserOnly="true"/>-->
If you allow access, you allow website to be viewed in webview (in this case ALL website).
With no access, all external link are open in native browser.
Use this
window.open('http://www.myurl.nl', '_blank', 'location=yes');