Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Javascript (https://www.askmehelpdesk.com/forumdisplay.php?f=452)
-   -   Force javascript newsfeed items to open in new window? (https://www.askmehelpdesk.com/showthread.php?t=131277)

  • Sep 19, 2007, 08:52 AM
    RickJ
    Force javascript newsfeed items to open in new window?
    I've got this javascript newsfeed on a webpage.

    Code:

    <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!
  • Sep 19, 2007, 09:24 AM
    Curlyben
    have you tried target="_blank"
  • Sep 19, 2007, 10:59 AM
    RickJ
    Yeah, tried it in a few places in there and none worked.
  • Sep 19, 2007, 11:16 AM
    retsoksirhc
    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
    Code:

    target="blank"
    To all the
    Code:

    <a href="http"//pagename/story.aspx">Link Text</a>
    That would be about it...
  • Sep 19, 2007, 11:23 AM
    RickJ
    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.
  • Sep 19, 2007, 01:20 PM
    jstrike
    Actually it's not really that bad with a few lines of JavaScript...
    Code:

    <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

  • All times are GMT -7. The time now is 07:34 PM.