在inappbrowser中打开_blank链接 [英] Opening _blank links inside inappbrowser

查看:236
本文介绍了在inappbrowser中打开_blank链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的cordova应用程序中有外部"锚链接,我们使用

We have 'external' anchor links in our cordova app, which we open using the _blank target of the inappbrowser plugin, which opens an inappbrowser instance 'above' the native app. These are generally links to our web-based support site.

现在,当用户位于不支持浏览器的支持网站上时,我们可以链接到使用标准target="_blank"的第三方网站.但是,用户看不到打开了inappbrowwser实例的新实例,也没有看到system浏览器实例的实例,而是单独的inappbrowser实例将其从支持站点转移到了第三方站点.

Now, when the user is on our support site in the inappbrowser, we have links to third-party sites that use the standard target="_blank". However, users are not seeing a new instance of the inappbrowwser open, nor a system browser instance open, but rather the lone inappbrowser instance takes them away from the support site to the third-party site.

有什么办法可以使target="_blank"的显示不正常行为正常工作?

Any way to have the inappbrowser behavior with target="_blank" work as expected?

推荐答案

按照InAppBrowser的设计,它只能有一个实例,因此,唯一的选择是在系统浏览器中打开外部链接. 您可以侦听loadstart事件,如果该URL不包含您的域,请在系统浏览器中将其打开,如下所示:

As InAppBrowser is designed, there can be only one instance of it, so your only choice is to open the external links on the system browser. You can listen for the loadstart event and if the url doesn't contain your domain then open it on the system browser, something like this:

var browserRef = window.cordova.InAppBrowser.open('http://www.yourdomain.com/support', '_blank');

browserRef.addEventListener('loadstart', function(event) {
    if((event.url).indexOf('www.yourdomain.com') === -1) {
        window.cordova.InAppBrowser.open(event.url, '_system');
    }
});

但是我认为这不会避免也将外部站点加载到inAppBrowser窗口中,因此您还必须注入javascript以返回到inAppBrowser的上一页

But I don't think that will avoid also loading the external site on the inAppBrowser window, so you will have to also inject javascript to return to the previous page on the inAppBrowser

browserRef.addEventListener('loadstop', function(event) {
    browserRef.executeScript({ code: 'window.history.back();' }, null);
});

这篇关于在inappbrowser中打开_blank链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆