我正在尝试在我的 Cordova 应用程序中打开一个外部 URL 链接。目前它使用模态视图呈现应用内浏览器,但是没有返回按钮或关闭按钮。用户在点击外部链接时实际上被卡住了。例如,当有人点击“访问网站”链接时,应用内浏览器会显示出来,网站也能正常显示,但没有方法可以回到应用程序,或者关闭应用内浏览器。我该如何解决这个问题?
<a href="http://www.sdtaproom.com/" target="_blank">Visit Website</a>
我看到有一个解决方案,window.open("http://stackoverflow.com", "_system");,但我不知道如何在href代码中实现它。
回答(已编辑):将此代码添加到 head 中的 script 标签中。
<script src="cordova.js"></script>
<script type="text/javascript">
window.addEventListener('load', function () {
$(document).on('click', 'a[target="_system"],a[target="_blank"]', function (e) {
e.preventDefault();
var url = this.href;
window.open(url,"_system");
});
}, false);
</script>