【问题标题】:How to access cordova functions from an IFrame in phonegap IOS如何从phonegap IOS中的IFrame访问cordova函数
【发布时间】:2014-02-04 09:37:22
【问题描述】:

在我的 Phonegap ios 项目中,我有一个 i 框架,而 iframe 的 src 是同一 www 文件夹中的本地 html 页面。在 html(IFrame 源代码)内有一个按钮和 onlick 侦听器。我需要在 InAppBrowser 或 safari(新窗口)中单击该按钮时打开一个网站。我无法从 html 文件(IFrame 源)访问 phonegap 方法,我在两个 html 文件中都包含了cordova,下面给出了我的源 html 页面,此页面显示在 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>

【问题讨论】:

    标签: ios iframe cordova cordova-3 inappbrowser


    【解决方案1】:

    在 iFrame 所在的“父”页面中,创建以下函数

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-18
      • 2018-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-19
      • 1970-01-01
      相关资源
      最近更新 更多