0

这是 phonegap 主文件www/index.html 我想像本地应用程序一样加载我的网站,脚本:

//var ref = cordova.InAppBrowser.open('http://website.com/page/index.php', '_self', 'location=no');
 document.addEventListener("deviceready", function(){
       window.open = cordova.InAppBrowser.open('http://website.com/page/index.php', '_self', 'location=no');
 },true);

</script>

我的 phonegap config.xml文件

<plugin name="cordova-plugin-inappbrowser" source="npm" spec="~1.3.0" />
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />

我的网站也在所有页面中启用

header('Access-Control-Allow-Origin: *');

脚本中的网站根本不是我的网站,因为我在本地主机上运行它,我用手机浏览器在同一网络中测试了网站,它工作得很好,但是当我尝试通过手机间隙应用程序加载时,它显示空白页面

4

1 回答 1

1

您的代码正在更改 windows.open() 的原型默认值,实际上并没有打开任何东西;

你需要的是:

window.open = cordova.InAppBrowser.open;//change default prototype to cordova
var ref = cordova.InAppBrowser.open(url, target, options);//inappbrwoser reference

然后你可以做 ref.close()、show()、hide() 等。

你也可以添加EventListener

于 2019-08-21T17:41:43.977 回答