简体   繁体   English

从服务器端页面访问Cordova插件

[英]Accessing Cordova plugins from server-side pages

I've setup Cordova and got a sample Android app running. 我已经安装了Cordova并运行了一个示例Android应用程序。 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. index.html页面启动时可以查询设备插件以显示,例如,初始index.html页面中的window.device.platform。

Thing is, my app is server-side rendered. 事实是,我的应用是在服务器端呈现的。 I will put into index.html the code: window.location="http://myserver.com/myServsidePages.html" 我将把index.html代码放入: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. 我还无法获取“ myserver.com/myServsidePages.html”页面来与windows.device对象或其他cordova插件进行交互。

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. 在一次尝试中,我在生成的cordova项目中的/ www / plugins文件夹中包含了cordova.js,cordova_plugins.js和所有其他javascripts文件,但是在我的服务器端javascript代码中仍然没有此windows.device对象。我向客户推。

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. 我最初的尝试是让index.html在客户端上准备设备(等待“ deviceready”),然后使用window.location ='...“重定向到服务器端页面-我期望'window.device'能够在这种情况下也可以定义和使用。

How can I re-direct my Cordova generated web app to external pages, and still address the device, from these external pages ? 如何将我的Cordova生成的Web应用程序重定向到外部页面,并且仍然可以从这些外部页面访问设备?

Thanks 谢谢

You have to get your rendered html using jQuery ajax call and then put them inside a div element like this: 您必须使用jQuery ajax调用获取呈现的html,然后将它们放入div元素中,如下所示:

  $.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() 有关更多信息, 请参见此页面: jQuery.get()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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