Remote html files with worked cordova.js + plugins

  • 1
  • Question
  • Updated 4 years ago
How add cordova.js in the remote server files ?

I use inappbrowser in the my app, but in some remote pages I need use plugins (such as lockOrientation).

In the config.xml I have:

What variants I can use for load cordova.js in this app ?
Photo of Андрій Чериця

Андрій Чериця

  • 4 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
-Cordova.js is added at the build time automatically. No need to add it manually, just give reference of it.
<script src="cordova.js" type="text/javascript"></script>
-While post your code, wrap it by code element.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Андрій,
you need a good reason to load file remotely. All assets should be stored locally, on the device. What are you trying to do? Phonegap is not webbrowser or a webservers.

Jesse
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Please guys, read the question again and don't pull the trigger too early.

The OP wants to use Cordova plugins in a website which is displayed in the inappbrowser window. [S]he believes that cordova.js, which is present in the app after Build, should be injected into that website.

Now, this can be done by using the iab-plugin's executeScript method to insert a reference to cordova.js. Since that file is not present on the server where the site comes from, the full local file path must be specified to reference it. And that path will be different for each OS.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
Got it. Phonegap is not webbrowser or a webserver.

OP thinks cordova.js can be loaded from the server.

I quote:
How add cordova.js in the remote server files ?
Photo of Андрій Чериця

Андрій Чериця

  • 4 Posts
  • 0 Reply Likes
All assets should be stored locally, on the device.

But my client wont save it only in the remote server.

OP thinks cordova.js can be loaded from the server.


I did it, just replace some code in the file: <script type="text/javascript" src="cordova.js"></script> To: <script type="text/javascript" src="file://platform_www/cordova.js"></script>
And this works for the Android and iOS. This will be anought for me.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Андрій,
again, all assets should be stored locally.

This means include those files in bundle you upload to Phonegap Build. The final APK will include those files you put in the bundle you uploaded.

I don't understand this sentence you wrote:
This will be anought for me.

Jesse
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
again, all assets should be stored locally.
You're still missing the point. The file cordova.js is 'injected' by PGB and thus it's available in the app locally. The OP, Andrej, knows that.
He wants to reference that file in his remotely hosted website while it is being loaded in the inappbrowser window.

I don't understand this sentence you wrote:
This will be anought for me.
Can't miss: that should be "enough".
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
I'm puzzled by your response. Does this OP really want to load via inappbrowser? Does the OP really want a bad design? My first sentences was:
You need a good reason to load file remotely.
I have not heard back on that. So I'll wait.

You might also notice this is the OP's first post.

Jesse
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
He wants to display a remote website in the inappbrowser window. That's exactly what that plugin is for and has nothing to do with either a bad design or loading app content from a remote source into the webview.

Andrej wrote:
I use inappbrowser in the my app, but in some remote pages I need use plugins (such as lockOrientation). which sounds perfectly clear: he needs to be able to use plugin functionality from his remote website while it is loaded/displayed using the inappbrowser plugin in the inappbrowser window. So, he figures, he needs the cordova.js file referenced in his remote site's html in such a way that it is fetched from the app's assets directory.
Photo of Андрій Чериця

Андрій Чериця

  • 4 Posts
  • 0 Reply Likes
@Petra V:
Thanks. You are understood me fully. And yes, I forgot say about inappbrowser. Thanks for advices.

@JesseMonroy650:
Yes, I need load file remotely becouse this want my administration(director).

Previosly I do all with local files, just load some data by json, but they want load all content from remote site. I do not can say anything, just obey orders.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Андрій,
okay thank you for the explanation. I understand. Please let your director know that doing this will make the app unreliable, unresponsive and insecure. It will also make it difficult to get into Android and iOS stores.

Please also inform your director of the following. From the FAQ Top Mistakes by Developers new to Cordova/Phonegap

Google and Apple frowns on using apps as wrappers for website

Quote Google Developer Program Policies - Spam and Placement in the Store

Do not post an app where the primary functionality is to:

Drive affiliate traffic to a website or
Provide a webview of a website not owned or administered by you (unless you have permission from the website owner/administrator to do so)

Quote Apple iTunes Guidelines - 2.12

Apps that are not very useful, unique, are simply web sites bundled as Apps, or do not provide any lasting entertainment value may be rejected


Please see my comment below on how to add remote files.

Jesse
Photo of Андрій Чериця

Андрій Чериця

  • 4 Posts
  • 0 Reply Likes
PS. If on the config.xml you are write

<content src="http:/frommysite.com/" />

And in the inside of all pages you are add in the header:

<script type="text/javascript" src="file://platform_www/cordova.js"></script>

You are get cordova.js for current platform. (Android works 100%, in iOS must works, not tested yet, andther platforms do not use).
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Hm....but that is NOT using the inappbrowser, here!

If this is what you are doing, then:
- I'm pretty sure at least Apple will reject it
- I agree with Jesse that it's bad 'design'
- your manager should realize that every user already has an app that can display his website even better. It's called a "browser".
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Андрій,
regardless of what design your director wants, some files MUST be loaded from the device - otherwise the app will be rejected outright for being insecure. Further loading files is the InAppBrowser is insecure, so Phonegap does NOT allow access any plugins; if available you can use HTML5 API services; or you can use any Javascript libraries generally available (like jquery, websocket, and others).

Okay to be clear, the file phonegap.js (or in your case cordova.js) must be loaded from the device. The file is expected to be loaded from the index.html on the device. After that and after the deviceready event, then in the inAppBrowser can be loaded. Following that it is required to use the whitelist plugin so that remote files can be loaded.

If this is completely clear, I will point to you to a worksheet for the whitelist plugin. Or do you have any questions?

Jesse
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
After that and after the deviceready event, then in the inAppBrowser can be loaded. Following that it is required to use the whitelist plugin so that remote files can be loaded.
The whitelist plugin (and whitelist rules in config) are not required when opening external content in the inAppBrowser window.

(Also, have you noticed that Andrej is NOT using the inAppBrowser window, although he believes he does?)
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
Whitelist is required under a few situations with inAppBrowser.
We've discussed this many times. I have not blogged it yet,
because it is an edge case. You should recall this.

Yes. I noticed he does not know what he is doing.

Jesse
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Whitelist is required under a few situations with inAppBrowser.
Yes, but only with the _self parameter, where the contents is displayed in the webview. The OP claimed he was using the inappbrowser window, though (which he isn't).
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Petra,
once the confusion is clear on the OP's end, then we can formulate a complete and correct response.
Jesse
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You mentioned a "few situations".
Can you please mention one other situation where the whitelist is relevant?