Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
diegoadrada
Posts: 18
Registered: ‎03-22-2013
My Carrier: N/A

Open a link on Playbook Browser.

Greetings, I am developing an app for BlackBerry Plabyook with rss news reader. I've been able to read the data and display the news list with its own title and description.
The link to go to the full story is in the title, that is, if you click on the title redirects to the full story in an external source.
When I test the app on the emulator Ripple, this works well, by clicking on the title of a news item from the list, it opens a new window in Chrome with the corresponding link of the news.
The problem is on the Playbook, as similarly shown correctly news list with its own title and description, but selecting the title to open the new link, it does nothing.
In the JavaScript file I have the following two lines of code:

link.setAttribute('href', entries[i].link);            
link.setAttribute('target','_blank');

If I leave only the first line of code, then the app does work and open the link. The problem is that it opens that link within the app and that's not the idea.

 

So I guess instead of the second line of code, I should add an instruction for the link to open in a new window of the browser app.

This is the JavaScript code I'm using to read the feed of news:

function myGetElementsByClassName(selector) {
    if ( document.getElementsByClassName ) {
        return document.getElementsByClassName(selector);
    }

    var returnList = new Array();
    var nodes = document.getElementsByTagName('div');
    var max = nodes.length;
    for ( var i = 0; i < max; i++ ) {
        if ( nodes[i].className == selector ) {
            returnList[returnList.length] = nodes[i];
        }
    }
    return returnList;
}

var rssReader = {
    containers : null,

    // initialization function
    init : function(selector) {
        containers = myGetElementsByClassName(selector);
        for(i=0;i<containers.length;i++){
            // getting necessary variables
            var rssUrl = containers[i].getAttribute('rss_url');
            var num = containers[i].getAttribute('rss_num');
            var id = containers[i].getAttribute('id');

            // creating temp scripts which will help us to transform XML (RSS) to JSON
            var url = encodeURIComponent(rssUrl);
            var googUrl = 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num='+num+'&q='+url+'&callback=rssReader.p...

            var script = document.createElement('script');
            script.setAttribute('type','text/javascript');
            script.setAttribute('charset','utf-8');
            script.setAttribute('src',googUrl);
            containers[i].appendChild(script);
        }
    },

    // parsing of results by google
    parse : function(context, data) {
        var container = document.getElementById(context);
        container.innerHTML = '';

        // creating list of elements
        var mainList = document.createElement('ul');

        // also creating its childs (subitems)
        var entries = data.feed.entries;
        for (var i=0; i<entries.length; i++) {
            var listItem = document.createElement('li');
            var title = entries[i].title;
            var contentSnippet = entries[i].contentSnippet;
            var contentSnippetText = document.createTextNode(contentSnippet);

            var link = document.createElement('a');
            link.setAttribute('href', entries[i].link);
            link.setAttribute('target','_blank');


            var text = document.createTextNode(title);
            link.appendChild(text);

            // add link to list item
            listItem.appendChild(link);

            var desc = document.createElement('p');
            desc.appendChild(contentSnippetText);

            // add description to list item
            listItem.appendChild(desc);

            // adding list item to main list
            mainList.appendChild(listItem);
        }
        container.appendChild(mainList);
    }
};

window.onload = function() {
    rssReader.init('post_results');
}

And here is the HTML:

<!DOCTYPE html>
<html>
<head>
    <title>News</title>
    <meta id="viewport" name="viewport" content="user-scalable=no,
    width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0;" />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="scripts/news.js">
    </script>
</head>

<body>
    <div id="content">
        <div class="news">
            <div class="post_results" id="post_results1" rss_num="20" rss_url="http://allafrica.com/tools/headlines/rdf/soccer/headlines.rdf">
                <div class="loading_rss">
                    <center><img alt="Loading..." src="images/loader.gif" /></center>
                </div>
            </div>
            <div style="clear:both;"></div>
        </div>
    </div>
</body>
</html>

 

I really appreciate any ideas or suggestions you may have.

 

 

 

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,465
Registered: ‎04-12-2010
My Carrier: Bell

Re: Open a link on Playbook Browser.

Unless I misunderstood, would the Browser invocation API be of use here?

http://developer.blackberry.com/html5/apis/blackberry.invoke.browserarguments.html

 

 


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.