Log in

View Full Version : RSS Feed Issue (Click in link will Open New Window)



asarker@eircom.ie
10-04-2017, 02:55 PM
Hi there,
I have an issue with current coding of RSS feed. I was able to get RSS feed from 3 news papers and I have setteled them in one page. but issue rises if I add that page to another page using <iframe> it doesnot open in full page, it just open within the page height. Now my question is it possible to open in full new window page when I will click a link from RSS Feed. This code below actully I took from Dynamic Drive RSS feed

link for the webpage that I have issue with - http://www.irelandawamileague.com/Rsfeedtest2.html


<div id="IrishNews"></div>

<div class="content"><script>
(function(c){
var uniquename = 'IrishNews' // id of target div
var query = 'select * from rss(0,5) where url = "https://www.irishtimes.com/cmlink/news-1.1319192"'; // query as explained in original version
var numretries = 30; // increase this number (number of retries) if you're still having problems

//////// No Need To Edit Beyond Here Unless You Want To /////////

var counter = typeof c === 'number'? c : numretries;
var thisf = arguments.callee;
var head = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
window["callback_" + uniquename + (--counter)] = function(r){
head.removeChild(s);
if(r && r.query && r.query.count === 0 && counter > 0){
return thisf(counter);
}
//r now contains the result of the YQL Query as a JSON
var feedmarkup = '<p>';
var feed = r.query.results.item // get feed as array of entries
for (var i=0; i<feed.length; i++){
feedmarkup += '<a href="' + feed[i].link + '">';
feedmarkup += feed[i].title + '</a><br />';
feedmarkup += feed[i].description + '</p>';
}
document.getElementById(uniquename).innerHTML = feedmarkup;
};
var baseurl = "https://query.yahooapis.com/v1/public/yql?q=";
s.src = baseurl + encodeURIComponent(query) + "&format=json&callback=callback_" + uniquename + counter;
head.append(s);
})();
</script> </div>


I am also attaching a screenshot of that RSS Feed news.

jscheuer1
10-04-2017, 11:27 PM
This is actually "unofficial code" that I wrote, not Dynamic Drive code. But it's based upon code from Dynamic Drive and/or JavaScriptKit.

First thing I'd suggest is notice this line:


feedmarkup += '<a href="' + feed[i].link + '">';

That's what creates the main link for each feed's item. If you want them to open up in a new tab, change to:


feedmarkup += '<a href="' + feed[i].link + '" target="_new">';

"_new" will establish a reusable window/tab for these links. If you want all of them to have their own window or tab, use "_blank".

If it's more of an issue of links within the feed items, that is links other than the main feed link, that can be dealt with in another way. Let me know.

The browser cache may have to be emptied and/or the page refreshed to see changes.



Alternatively, you could add the lines as shown (highlighted):


document.getElementById(uniquename).innerHTML = feedmarkup;
var feedlinks = document.getElementById(uniquename).getElementsByTagName('A'), a = -1;
while(++a < feedlinks.length){
feedlinks[a].target = '_blank';
}

same caveat about _blank vs _new as in my previous idea. This one, however, will get all links in each feed item, not just the main item link.

asarker@eircom.ie
10-05-2017, 12:32 PM
Hi jscheuer1,
Thanks very much. Only the one line of code on top sorted out the issue. Lets see, if its working fine after few updates on news.

Thanks