我正在为BB10,android,iod,windows8开发cordova应用程序。
其中我要求在默认设备浏览器中打开网址。
因为我使用过org.apache.cordova.inappbrowser插件。
但在使用之后我遇到了从浏览器返回时重新启动应用程序的问题。 [除了windows8之外的所有平台的问题]
所以我使用了以下解决方案,
jQuery(document).delegate('.external', 'click', function(e) {
window.open(e.target.href, '_system', 'location=yes');
e.preventDefault();
});
<a class="external" href="myUrl">Track Now</a>
以上解决方案, Android:它工作正常。 Blackberry10问题:在外部浏览器中没有打开Url它只在app浏览器中打开, IOS问题:url根本不工作(当我点击链接时没有发生任何事情)。
所以,非常感谢你身边的任何帮助。
答案 0 :(得分:4)
以下是我案例的解决方案。 它在所有Android,BlackBerry10和IOS平台上都运行良好。
通过添加黑莓调用插件来解决黑莓问题。
function openBlackBerryBrowser(url) {
function onInvokeSuccess() {
alert("Invocation successful!");
}
function onInvokeError(error) {
alert("Invocation failed, error: " + error);
}
blackberry.invoke.invoke({
target: "sys.browser",
uri: url
}, onInvokeSuccess, onInvokeError);
}
if (window.device.platform.toLowerCase().indexOf('blackberry') > -1) {
jQuery(document).delegate('.external', 'click', function(e) {
openBlackBerryBrowser(e.target.href);
});
} else {
jQuery(document).delegate('.external', 'click', function(e) {
e.preventDefault();
var ref = window.open(e.target.href, '_system', 'location=yes');
});
}
希望这会对某人有所帮助。
答案 1 :(得分:0)
在我看来,没有必要使用jquery来做到这一点。你可以尝试这样的东西,但我只在Android和iOS上测试过:
在您的控制器中:
$scope.openLink = function(url){
window.open(url, '_system');
};
HTML:
<a href="#" ng-click="openLink('http://www.google.com')">www.google.com</a>
让我知道BB的作品是否也有效!