PhoneGap / Cordova 2.3 .:如何打开InAppBrowser中的所有外部链接? [英] PhoneGap/Cordova 2.3.: how to open all external links in InAppBrowser?

查看:100
本文介绍了PhoneGap / Cordova 2.3 .:如何打开InAppBrowser中的所有外部链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Sencha Touch 2和Cordova 2.3.0开发移动应用程序。
我想能够打开所有外部链接(从动态加载的HTML)到新的InAppBrowser。



有没有办法实现这个修改所有外部链接以包含target =_ blank?



我想拦截外部链接的点击,并使用来自InAppBrowser的window.open API打开它们。
既然我的目标是iOS和Android,我想javascript解决方案最好避免单独的代码(Java和Objective-C)。



谢谢! / p>

更新:我刚刚发现:
https: //gist.github.com/4694032



唯一的麻烦是我不在我的应用程序中使用jQuery。

解决方案

  Ext.each Ext.query('a'),function(el){
el = Ext.get(el);
el.on('click',function(e){
e。 preventDefault();
console.log('clicked',el.getAttribute('href'));
});
});


I am developing a mobile app using Sencha Touch 2 and Cordova 2.3.0. I would like to be able to open all external links (from dynamically loaded HTML) into the new InAppBrowser.

Is there a way to achieve this without having to modify all external links to contain target="_blank"?

I would like to intercept clicks on external links and open them using the window.open API from InAppBrowser. Since I target both iOS and Android, I guess a javascript solution would be better to avoid separate codes (Java and Objective-C).

Thanks!

update: I just found this: https://gist.github.com/4694032

The only trouble with this is that I don't use jQuery in my app. Is it worth it to include it just for this matter?

解决方案

Ext.each(Ext.query('a'), function(el) {
    el = Ext.get(el);
    el.on('click', function(e) {
        e.preventDefault();
        console.log('clicked', el.getAttribute('href'));
    });
});

这篇关于PhoneGap / Cordova 2.3 .:如何打开InAppBrowser中的所有外部链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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