[英]Dynamically load index.html in Phonegap Application
I am beginner to phonegap. 我是新手。 I want to create layout inside index.html which is driven by javascript and also having cordova to use apis in app.
我想在index.html中创建由javascript驱动的布局,并且还希望cordova在应用程序中使用api。 I am able to run hard coded index.html but I want to run as a live site inside phonegap and also want to use cordova plugins inside my live site.
我可以运行硬编码的index.html,但我想在phonegap中作为实时站点运行,并且还想在我的实时站点中使用cordova插件。
Can anybody help me or any idea to how I use live site or dynamic html through javascript? 任何人都可以帮助我,或者对我如何通过JavaScript使用实时网站或动态html有任何想法吗?
Thanks in advance, 提前致谢,
Vijay Barnwal 维杰·班瓦尔
You can load a live website by any of these 3 methods: 您可以通过以下三种方法之一来加载实时网站:
Embed an HTML iframe <iframe src="http://example.com"></iframe>
, for this to work, you will need to enable Cross-Origin Resource Sharing on your device and on your web server. 嵌入HTML iframe
<iframe src="http://example.com"></iframe>
,要使其正常工作,您将需要在设备和Web服务器上启用跨域资源共享。 Read Cordova 3.5.0 Whitelist Guide and for server, I want to add CORS support to my server . 阅读《 Cordova 3.5.0白名单指南》 ,对于服务器, 我想向服务器添加CORS支持 。
Use metatag to redirect the user to the desired URL. 使用元标记将用户重定向到所需的URL。
<meta http-equiv="refresh" content="0; url=http://example.com/" />
If you still need to use all the Cordova functions and plugins, the only way to do it is by loading the website using AJAX into a <div>
tag. 如果仍然需要使用Cordova的所有功能和插件,唯一的方法是使用AJAX将网站加载到
<div>
标签中。 Read: Ajax/jQuery - Load webpage content into a div on page load? 阅读: Ajax / jQuery-在页面加载时将网页内容加载到div中? Note: You still need to enable CORS for this to work.
注意:您仍然需要启用CORS才能使其正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.