I have a Phonegap app, that would open an external URL with super.loadUrl("http://example.com/index.html")
On that page I have included some Javascript code for a Phonegap Plugin. Is it possible to call a plugin from external Javascript file? I don't see why shouldn't work, but it doesn't.
My plugin is FileTransfer plugin. When I run the app with a local index.html all works fine, but I need to run an external script which calls the FileTransfer plugin. Is that possible? Does anybody tried it before ?
I asked in the Phonegap IRC and they say NO. Of course this could be a big security threat.
I also asked if it would be possible to include internal JS scripts in my external HTML file. And the answer is also NO. The best way is to turn the web app into an native app, and have all the scripts locally.
Related
I have a website in place and I would like to load it into a webview giving the site a native feel.
Now, this is fairly simple to do using window.location='url' but when the site loads the javascript on the site is not able to access plugin apis. So it seems the site is running within a sandbox... unable to access cordova apis.
Is there a way to provide an externally loaded website access to the cordova apis?
I load my external site using <content src="http://myurl"/> in my config.xml
Yes, you can do it. Upload all the cordova.js and plugin files from the project to your server, then in the pages on your server just include it. Be sure to keep them in the same relative folders as they are in the project.
<script type="text/javascript" src="cordova.js"></script>
(Note that I have done this on versions 3 to 5, but not in 6 yet.)
I'm developing an cordova app for Android which has a lot of logic (js) and design (html/css) same as my web application. I want to share these assets among web app and android app. Now I had compiled all these js and css in apk, but when some code is changed, I have to prepare an update and put in the play store. If it would be possible to load code and css from server after app started, it would reduce need for upgrading. Is there any way?
I'm considering loading shared resources via ajax and dynamically creating stylesheets and scripts in DOM, but maybe there is better approach, isn't it?
You could download the files from server every time, but i think that is not what you want because it would not be availibe offline at all and if the app it big and the connection bad it will take much time to download.
a better way is to download the files if they change. you can do that with FileTransfer.download() yourself or use a ready solution like the cordova-standalone-hydration
BUT your app will not be accepted by for example Apple because they deny an app with code they can not check
I found a plugin where you can update all your files in the WWW folder on startup or later.
Link: https://www.npmjs.com/package/cordova-plugin-dynamic-update
I am trying to use this File Tree For my Apache Cordova Application.
As it cannot contain any server side scripts, the script must be placed into a seperate project and be called from the client side (apache cordova app).
So that means I need to call the script with Ajax jquery and display the files.
How do I do it using this JqueryFile browser JQuery fileTree?
I can suggest 2 approaches.
1) Use Cordova File api to get a list of directories/files to render a file tree in your JS application(i.e. Populate jQuery file tree)
http://docs.phonegap.com/en/edge/cordova_file_file.md.html#DirectoryReader
2) I have not used this plugin myself, but you can use a Cordova plugin like below to access the native file system:
Cordova Plugin File
You can not run a JavaScript library on the native side, you'd need to write code in ObjectiveC/Swift for iOS or Java for Android and create a plugin like above.
I am developing Web Application using MEAN(Mongo, Express, Angular, Node) JS stack.
I would like to use PhoneGap to compile my clients for Android/iphone native app. At the same time I want to keep same client-side Views & AngularJS code to remain usable for desktop browsers. I am using bootstrapper for Responsive design and it works fine for me on mobile browsers.
I saw, Phonegap require us to include some of it's own Javascript files, and I will be required to have few more .js files in footer of index.html.
If I pressume, I should not be using server side .jade engine for index.html file, and all my .html should remain in client side.
will index.html created for phoneGap will cause problem, if I use it for desktop browser? Should I have different index.html for browser and phoneGap input. Can grunt help me in customizing index.html files.
What are the other things which I should take care of for my needs?
My advice for you is to separate the projects, Phonegap or Cordova Apps doesn't have a running server, they serve the html files through the file:// protocol.
If I pressume, I should not be using server side .jade engine for
index.html file, and all my .html should remain in client side.
You presumed correctly, no .jade templates should be used, your views should be plain html files or, if you want, load them as scripts so you don't have to load them on page request increasing app performance.
will index.html created for phoneGap will cause problem, if I use it
for desktop browser? Should I have different index.html for browser
and phoneGap input. Can grunt help me in customizing index.html files.
Yes it will, if you try to use an index,html from phonegap on a desktop browser you will get a lot of javascript alerts. Since phonegap.js is expecting to get some events that are fired by cordova when running on the device. And this gets worse if you have Cordova plugins.
I want to provide some functionality through an extension. This requires (read and execute) access to some resource files (an mp3 file, a swf file and two js).
I know user scripts cannot access local files and I need an extension (add-on) to do that.
But can I start by writing a greasemonkey script and compiling it to a xpi?
How should I specify the path to the file for it to work when compiled into an xpi?
This question is close to what I'm trying to do, but does not say anything about the path.
Yet this other question discusses how to add resources to your xpi, but assumes you write the xpi from scratch not if you compile a greasmonkey user script to an xpi
I am not familiar with greasemonkey, however I have successfully written to files using a FireFox addon. Once you have a FireFox addon which you can modify, you can see the page here: File I/O - MDC for some help writing files via the API in FireFox. I use the nsiFilePicker service to select the file/path.