问题描述:

Enviroment:

1. Android 4.0.3

2. PhoneGap 2.9.0

3. HTML5

Use-case

1. An existing WWW Web Site

2. PhoneGap application having it's "super.loadUrl" set to the WWW URL ( not local FS )

3. Javascript detects when running as an app

4. Extended App functionality is executed by the WebSite, eg. specialized video capture Activity usage

Problems:

When lunching the WebSite as in PhoneGap framework I try to load cordova.js:

( ), Unfortunately, this cause a security exception.

What is the best approach to support the above mentioned use-case ?

网友答案:

Keep in mind that Cordova/PhoneGap was not written to allow you to turn websites into apps - the site will probably look and behave poorly. It's best to use a "mobile first" strategy and design your mobile presence either first or separately from the website. You'll probably be spending a lot of effort redesigning and tweaking your website to work with Cordova when it'd be better to just spend the effort to build the web application from scratch.

If you insist on doing it the way you describe (loading the website immediately by changing the super.loadURL() - btw, you should not be changing super.loadURL() but instead changing the <content src=""> tag in /res/xml/Config.xml), then you'll probably have to upgrade to the latest Cordova to pick up some fixes that will help you load cordova.js over the wire.

网友答案:

From InAppBrowser documentation:

"NOTE: The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs."

Maybe you can use an iframe to load your website from a local html document that actually loads cordova.js locally.

See http://stackoverflow.com/a/16660136/3429223 for reference, should it help.

Best.


EDIT:

Totally agree with MBillau's answer. Trying to load an external website as a Phonegap/Cordova app is not an orthodox use case, that may arise several security concerns. Best approach is to design specific version for the app.

相关阅读:
Top