简体   繁体   中英

Accessing Cordova plugins from server-side pages

I've setup Cordova and got a sample Android app running. the index.html page start up with is able to interrogate the device plugin to display, for example, the window.device.platform in the initial index.html page.

Thing is, my app is server-side rendered. I will put into index.html the code: window.location="http://myserver.com/myServsidePages.html"

so that server-side web pages can be served.

I've have not been able to get my 'myserver.com/myServsidePages.html' pages to interact with the windows.device object or the other cordova plugins.

In one attempt, I've included cordova.js, cordova_plugins.js and all other javascripts files from the /www/plugins folder in the generated cordova project, but still this windows.device object is not available in my server-side javascript code I push to the client.

My original attempt was to have index.html prepare the device on the client (wait for 'deviceready') and then redirect using window.location='..." to server-side pages - I was expecting 'window.device' to be defined and available in that scenario too.

How can I re-direct my Cordova generated web app to external pages, and still address the device, from these external pages ?

Thanks

You have to get your rendered html using jQuery ajax call and then put them inside a div element like this:

  $.get( "http://www.yourserverpageurl.com/ajax/test.html", function( data ) {
       $( ".result" ).html( data );
       alert( "Load was performed." );
  });

For more information have a look at this page: jQuery.get()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM