How to access cordova functions from an IFrame in phonegap IOS

烈酒焚心 提交于 2019-12-08 00:52:08

问题


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>

回答1:


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

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

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

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


来源:https://stackoverflow.com/questions/21548677/how-to-access-cordova-functions-from-an-iframe-in-phonegap-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!