在我的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>
最佳答案
在iFrame所在的“父”页面中,创建以下函数
function popnew(path) {
navigator.app.loadUrl(link, { 'openExternal' : true });
}
然后为iFrame中的任何按钮/链接调用上述函数
<button onclick="javascript:parent.popnew('http://www.stackoverflow.com')"></button>
关于ios - 如何从Phonegap IOS中的IFrame访问Cordova功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21548677/