如何从科尔多瓦应用程序内外部站点获取数据?

问题描述:

情景:

我在 angularJS 提出的申请和离子科尔多瓦3.5 结果
该应用程序加载槽的iframe网络做出一些事情一步步的形式。这是网络上的其他网站。

I've an application made in angularJS and ionic for cordova 3.5
This application loads trough an iframe a web to make some things with a step by step form. This web is on other site.

在code的HTML是:

The code for the html is:

<div id="IframeContainer">  

 <iframe src="URL" style="width:100%;height:90%" onLoad="checkforclose(this);"></iframe>

</div>

这一步一步的形式返回科尔多瓦应用程序需要知道的形式会发生什么结果。它可以返回一个JSON,一个纯文本/或甚至是HTML自动投递到另一个站点(这与本次非回答问题链接:邮政和重定向从网页API

This step-by-step form returns a result that the cordova application needs to know what happens in the form. It can return a json, a text/plain or even an HTML that auto-post to another site (This is linked with this non-answered question: Post and redirect FROM Web Api)

说到这,在我的科尔多瓦的应用程序我有一个JavaScript函数,以关闭iframe和再次接管我的应用程序的控制,检测如果URL中包含单词关闭。这是code:

Said this, in my cordova application I've a javascript function in order to close the iframe and take over again the control of my application, detecting if the url contains the word "close". This is the code:

<script type="text/javascript">
function checkforclose(pageURL) { 
    var urlFrame = pageURL.contentWindow.location;
    if (urlFrame.href.indexOf('close') > -1) {
    window.location = "#/employees/";
        }
}   
</script>


问:

试图避免CORS(所以我觉得我不能读取负载的iframe中的内容,或者我错了?),结果
不使用jQuery(AngularJS是值得欢迎的,更普通的JavaScript)结果
接管控制再次应用

Trying avoid CORS (So I think I can't read the iframe content on load, or I'm wrong?),
without using jQuery (AngularJS is welcome, plain javascript even more)
Taking over the control again to the application

我怎样才能获得通过一步一步的外在形式返回的数据?

更新1:结果
我试着编写一个的onload读书(CORS错误),并张贴到科尔多瓦,html页面,但没有任何结果可敬

UPDATE 1:
I tried coding a "onload" reading (CORS errors), and posting to a cordova-html page, but without any respectable result.

一个可能的解决方案是 Web消息或交叉-document消息。下面是一个博客文章如果有人用这种方法从在iframe加载外部页面访问移动设备的摄像头。虽然这个人了相反的目标(从科尔多瓦获取数据在iframe中加载页面),他们能够做到在一个iframe,科尔多瓦页面之间的跨域通信;这就是我相信你正在尝试做的。

A possible solution is Web messaging or cross-document messaging. Here's a blog post where someone used this method to gain access to a mobile device's camera from an external page loaded in an iframe. Although this person had the opposite goal (get data from Cordova to page loaded in iframe), they were able to accomplish cross domain communication between a page in an iframe and Cordova; which is what I believe you are trying to do.