Log in

View Full Version : Force javascript newsfeed items to open in new window?


RickJ
Sep 19, 2007, 08:52 AM
I've got this javascript newsfeed on a webpage.


<SCRIPT language=JavaScript src='http://www.gop.com/Feeds/NewsFeed-Wide.aspx'></SCRIPT>

Is there a way to make the link items in it open in a new window/tab?

Thanks!

Curlyben
Sep 19, 2007, 09:24 AM
have you tried target="_blank"

RickJ
Sep 19, 2007, 10:59 AM
Yeah, tried it in a few places in there and none worked.

retsoksirhc
Sep 19, 2007, 11:16 AM
Since you're not actually controlling the feed page yourself, there isn't really any easy way to do it.

You could write a server side script that reads the news page, sorts through it, and adds a

target="blank"
To all the

<a href="http"//pagename/story.aspx">Link Text</a>

That would be about it...

RickJ
Sep 19, 2007, 11:23 AM
Thanks sirhC.

That hurt my brain to read it :) so I'll just nix the feed. Not that important to have it on my site... I just discovered it while rooting around the supplier's site.

jstrike
Sep 19, 2007, 01:20 PM
Actually it's not really that bad with a few lines of JavaScript...


<div id="newsSource">
<SCRIPT language=JavaScript src='http://www.gop.com/Feeds/NewsFeed-Wide.aspx'></SCRIPT>
</div>
<script>
var regExp = /<a /ig;
var newsFeed = document.getElementById("newsSource");
var newsFeedSrc = newsFeed.innerHTML;
newsFeedSrc = newsFeedSrc.replace(linkRegEx,"<A target='_blank' ");
newsFeed.innerHTML = newsFeedSrc;
</script>

Every link in the feed will now open in a new browser window, even the gop.com link in the footer.

HTH,
-Jeff