打开一个URL在一个新的浏览器窗口,在Android中使用PhoneGap的工作 [英] Opening an url in a new browser window in Android working with PhoneGap

查看:111
本文介绍了打开一个URL在一个新的浏览器窗口,在Android中使用PhoneGap的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个应用程序,这需要将数据从RSS源(XML),这意味着我没有什么自带的控制权,我使用的是谷歌的API供稿检索数据JSON格式,我使用jQuery(feeder.js)生成生成的HTML的信息。

I've working on an app, that takes data from a RSS feed (xml), this means I don't have control of what comes with it, I'm using the Google Api for feeds to retrieve the data in JSON format, and I'm using jQuery (feeder.js) to generate the resulting html with the info.

生成的HTML进入我的PhoneGap项目中,一切工作得很好。

The resulting html goes inside my PhoneGap project, and everything works just fine.

现在唯一的问题是,里面从RSS检索到的信息,有时那里有一些链接去任何地方(如:Facebook,Twitter的,个人网站,报纸等)。

The only problem now is that inside the info retrieved from the RSS, sometimes theres some links going anywhere (eg: facebook, twitter, personal sites, newspapers, etc).

馈线提供了所有的元素里面的内容,包括标题,段落,链接和这样的。

The feeder provides all the content inside an element, containing the titles, paragraphs, links and such.

我现在需要的,是一种针对文章这里面的链接,并调用window.open事件,或其他工程来打开外部浏览器的链接。

What I need now, is a way to target this links inside the articles, and call the window.open event, or whatever works to open the link in an external browser.

由feeder.js生成的HTML结构是这样的:

The html structure generated by feeder.js goes like this:

<article>
    <h2>Title</h2>
    <p>Content</p>
    <a href="http://facebook.com">This link here!</a>
    <p>More content</p>
</article>

正如你所看到的,世界上没有class和id,瞄准一个单一的元素,因为它们出现正如在这里。

As you can see, theres no class or id, to target a single element, as they appear as pointed here.

我正在使用Android SDK和PhoneGap的对这个日期的最新版本。

I'm working with the latest versions of Android SDK and PhoneGap to this date.

基本上我需要做的,是针对元素&lt;一>内的&lt;文章>并给他们新的浏览器窗口中的事件。

Basically what I need to do, is to target the element < a > within the < article > and give them the new browser window event.

最好的问候的人谁需要一分钟来帮助我,干杯!

Best regards to anyone who takes a minute to help me, cheers!

推荐答案

在这里和谷歌研究了很多之后,我想出了以下内容。

After researching a lot here and google, I came up with the following.

随着我的应用程序中显示的内容,有一个返回按钮,用onClick事件,我用这个按钮可以定义一个函数调用,并针对文章内的链接事件。顺便说一下按钮有一个#href属性。

Along with the content displayed in my app, there is a back button, with an onClick event, I used this button to define a function and call the event targeting the link inside the article. By the way the button had a # href attribute.

这样做后,我通过ATTR补充说:onClick事件,后来只剩下一个#href属性。

After doing this, I added the onClick event via "attr", and later left the href attribute with a #.

该脚本去如下:

   function button(){
        var button = $(location).attr('href');
        button = button+'#';
        $('#articles a').each(function(){

              if(this != button){
                    $(this).attr("onClick", "navigator.app.loadUrl('"+this+"', { openExternal:true });");
                    $(this).attr("href", "#");  
                }
            });
    }

在onClick的,我称之为事件打开新的浏览器窗口,这在我的版本的PhoneGap的是navigator.app.loadUrl

Inside the onClick, I called the event for opening the new browser window, which in my version of phonegap was "navigator.app.loadUrl"

现在每次HTML加载RSS提要的内容,并附带了一些链接里面显示的:

Now every time the html loads the RSS feed content, and it comes with some link inside it display this:

&LT;一的onclick =navigator.app.loadUrl(' https://google.com/ ',{openExternal:真} );>链接&LT; / A>

< a onclick="navigator.app.loadUrl('https://google.com/', { openExternal:true });">Link< /a>

这将打开一个对话框,用户可以选择他想要使用的浏览器。

This opens a dialog box, where the user can pick the browser he wants to use.

再次感谢的人采取的麻烦,回答我的问题!

Thanks again to the people taking the trouble to answering my question!

这篇关于打开一个URL在一个新的浏览器窗口,在Android中使用PhoneGap的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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