【发布时间】:2016-05-07 12:35:20
【问题描述】:
我想知道如何在嵌入 webview 的应用程序上下文中打开一个 url。目前这个演示将在外部浏览器中打开一个新标签,所以,不是我所期望的。我使用 google.com 只是为了测试。
总结一下,我在找功能演示。
<?xml version="1.0" encoding="UTF-8"?>
<!-- config.xml reference: https://build.phonegap.com/docs/config-xml -->
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
xmlns:android = "http://schemas.android.com/apk/res/android"
id = "com.xxx.xxxxx"
version = "1.0.0">
<preference name="stay-in-webview" value="true" />
<access origin="*" browserOnly="true" subdomains="true" />
<content src="index.html" />
<allow-navigation href="https://google.com/*" />
<gap:plugin name="cordova-plugin-whitelist" source="npm" version="~1" />
<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="org.apache.cordova.splashscreen" />
<preference name="phonegap-version" value="cli-5.4.1" />
<preference name="permissions" value="none"/>
<preference name="target-device" value="universal"/>
<preference name="fullscreen" value="true"/>
</widget>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/index.css" />
</head>
<body>
<div>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.location.href = 'https://google.com';
}
</script>
</div>
<script type="text/javascript" src="cordova.js"></script>
</body>
</html>
更新: 完整的xml文件: https://codeshare.io/Vw3Fl
【问题讨论】:
-
1.您拥有的代码将永远无法工作。 2. 如果您打开一个外部 URL 以便您的应用程序作为网站包装器工作,您的应用程序可能会被应用商店拒绝。 Cordova/Phonegap 的一个常见错误是When designing the app, thinks phonegap works like a website or webbrowser.
-
@jcesarmobile 目前的问题是 SO。带有 InAppBrowser 的 window.open 在 android 中运行良好,您的答案也适用。然而,两者都在 ios 中失败了。在 iphone 中,我什么时候应该打开 webview 得到白页。
标签: android cordova webview phonegap-plugins phonegap-build