如何从phonegap IOS中的IFrame访问cordova函数 [英] How to access cordova functions from an IFrame in phonegap IOS

查看:281
本文介绍了如何从phonegap IOS中的IFrame访问cordova函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Phonegap ios项目我有一个i帧和src的iframe是同一个www文件夹中的本地html页面。里面的html(IFrame源)一个按钮和onlick监听器。我需要打开一个网站,而在InAppBrowser或safari(新窗口)中单击该按钮。我不能够从html文件(IFrame源),我包括cordova的两个html文件,我的源html页面给予的下面,这个页面显示在iframe。

IN my Phonegap ios project i have an i frame and src of Iframe is a local html page within the same www folder . inside the html (IFrame source) one button and onlick listener. i need to open one website while clicking that button in InAppBrowser or in safari (new window). i cannot able to access phonegap methods from the html file (IFrame source), i includeed cordova on both html files, my source html page given bellow, this page is shown in an Iframe.

<html>

<head>

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script src="js/libs/jquery.js"></script>
<script src="adv.js"></script>

<script>


  $(document).ready(function () {

      $('#advArea').find('button').on('click', function (e) {
                                 e.preventDefault();
                                 var path = "http://www.google.com");

                                 console.log(path);
                                 //window.open(path,'__system');
                                 //need to acces inApp Browser from here

                                 })

  });

</script>
</head>

<body>
<div id="advArea">

 <button></button>
  </div>
</body>

</html>


推荐答案

在您的iFrame的创建以下函数

In your "parent" page where your iFrame is, create the below function

function popnew(path) {
        navigator.app.loadUrl(link, { 'openExternal' : true });
    }

然后你为iFrame中的任何按钮/链接调用上述函数



then you call the above function for any button/link in the iFrame

<button onclick="javascript:parent.popnew('http://www.stackoverflow.com')"></button>

这篇关于如何从phonegap IOS中的IFrame访问cordova函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆