By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,080 Members | 1,845 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,080 IT Pros & Developers. It's quick & easy.

Help changing RSS feed window target

P: 49
I have an RSS reader that I have been using, but the only problem i have is that I want the target to be "_blank" rather than the parent window.

Anyone know where I should add the _blank?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <link href="rss.css" rel="stylesheet" type="text/css"/>
  3. <body>
  4.  
  5. <%
  6. Response.Expires = -1
  7.  
  8. ' =========== RSS2HTML.ASP for ASP/ASP.NET ==========
  9. ' copyright 2005-2008 (c) www.Bytescout.com
  10. ' version 1.27, 17 August 2008
  11. ' =========== configuration =====================
  12. ' ##### URL to RSS Feed to display #########
  13. URLToRSS = "http://rss.cnn.com/rss/cnn_topstories.rss"
  14.  
  15. ' ##### max number of displayed items #####
  16. MaxNumberOfItems = 10
  17.  
  18. ' ##### Main template constants
  19. MainTemplateHeader = "<table>"
  20. MainTemplateFooter = "</table>"
  21. ' #####
  22.  
  23. ' ######################################
  24. Keyword1 = "" ' Keyword1 = "tech" - set non-empty keyword value to filter by this keyword
  25. Keyword2 = "" ' Keyword1 = "win" - set non-empty keyword value to filter by this 2nd keyword too
  26. ' #################################
  27.  
  28. ' ##### Item template.
  29. ' ##### {LINK} will be replaced with item link
  30. ' ##### {TITLE} will be replaced with item title
  31. ' ##### {DESCRIPTION} will be replaced with item description
  32. ' ##### {DATE} will be replaced with item date and time
  33. ' ##### {COMMENTSLINK} will be replaced with link to comments (if you use RSS feed from blog)
  34. ' ##### {CATEGORY} will be replaced with item category
  35. ItemTemplate = "<tr><td><strong>{DATE}</strong><br/><strong>{CATEGORY}<br/></strong><a href=" & """{LINK}""" & ">{TITLE}</a><BR>{DESCRIPTION}</td></tr>"
  36.  
  37. ' ##### Error message that will be displayed if not items etc
  38. ErrorMessage = "Error has occured while trying to process " &URLToRSS & "<BR>Please contact web-master"
  39.  
  40. ' ================================================
  41.  
  42. Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
  43. xmlHttp.Open "GET", URLToRSS, false
  44. xmlHttp.Send()
  45. RSSXML = xmlHttp.ResponseText
  46.  
  47. Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")
  48. xmlDOM.async = False
  49. xmlDOM.validateOnParse = False
  50. xmlDom.resolveExternals = False
  51.  
  52. If not xmlDOM.LoadXml(RSSXML) Then
  53. ErrorMessage = "Can not load XML:" & vbCRLF & xmlDOM.parseError.reason & vbCRLF & ErrorMessage
  54. End If
  55.  
  56. Set xmlHttp = Nothing ' clear HTTP object
  57.  
  58. Set RSSItems = xmlDOM.getElementsByTagName("item") ' collect all "items" from downloaded RSS
  59.  
  60. RSSItemsCount = RSSItems.Length-1
  61.  
  62. ' if not <item>..</item> entries, then try to get <entry>..</entry>
  63. if RSSItemsCount = -1 Then
  64. Set RSSItems = xmlDOM.getElementsByTagName("entry") ' collect all "entry" (atom format) from downloaded RSS
  65. RSSItemsCount = RSSItems.Length-1
  66.  
  67. End If
  68.  
  69. Set xmlDOM = Nothing ' clear XML
  70.  
  71.  
  72. ' writing Header
  73. if RSSItemsCount > 0 then
  74. Response.Write MainTemplateHeader
  75. End If
  76.  
  77. j = -1
  78.  
  79. For i = 0 To RSSItemsCount
  80. Set RSSItem = RSSItems.Item(i)
  81.  
  82. ' fix for the issue when a description from a previous item 
  83. ' is used if current item description is empty provided by George Sexton
  84. RSSdescription="&nbsp;" 
  85. RSSCommentsLink="&nbsp;"
  86.  
  87. for each child in RSSItem.childNodes
  88.  
  89. Select case lcase(child.nodeName)
  90. case "title"
  91. RSStitle = child.text
  92. case "link"
  93. If child.Attributes.length>0 Then
  94. RSSLink = child.GetAttribute("href")
  95. if (RSSLink <> "") Then
  96. if child.GetAttribute("rel") <> "alternate" Then
  97. RSSLink = ""
  98. End If
  99. End If
  100. End If ' if has attributes
  101. If RSSLink = "" Then
  102. RSSlink = child.text
  103. End If
  104. case "description"
  105. RSSdescription = child.text
  106. case "content" ' atom format
  107. RSSdescription = child.text
  108. case "published"' atom format
  109. RSSDate = child.text
  110. case "pubdate"
  111. RSSDate = child.text
  112. case "comments"
  113. RSSCommentsLink = child.text
  114. case "category"
  115. Set CategoryItems = RSSItem.getElementsByTagName("category")
  116. RSSCategory = ""
  117. for each categoryitem in CategoryItems
  118. if RSSCategory <> "" Then
  119. RSSCategory = RSSCategory & ", "
  120. End If
  121.  
  122. RSSCategory = RSSCategory & categoryitem.text
  123. Next
  124. End Select
  125. next
  126.  
  127. ' now check filter
  128. If (InStr(RSSTitle,Keyword1)>0) or (InStr(RSSTitle,Keyword2)>0) or (InStr(RSSDescription,Keyword1)>0) or (InStr(RSSDescription,Keyword2)>0) then
  129.  
  130. j = J+1
  131.  
  132. if J<MaxNumberOfItems then
  133. ItemContent = Replace(ItemTemplate,"{LINK}",RSSlink)
  134. ItemContent = Replace(ItemContent,"{TITLE}",RSSTitle)
  135. ItemContent = Replace(ItemContent,"{DATE}",RSSDate)
  136. ItemContent = Replace(ItemContent,"{COMMENTSLINK}",RSSCommentsLink)
  137. ItemContent = Replace(ItemContent,"{CATEGORY}",RSSCategory)
  138.  
  139. Response.Write Replace(ItemContent,"{DESCRIPTION}",RSSDescription)
  140. ItemContent = ""
  141. RSSLink = ""
  142. End if
  143. End If
  144.  
  145. Next
  146.  
  147. ' writing Footer
  148. if RSSItemsCount > 0 then
  149. Response.Write MainTemplateFooter
  150. else
  151. Response.Write ErrorMessage
  152. End If
  153.  
  154. ' Response.End ' uncomment this for use in on-the-fly output
  155. %>
  156.  
  157.  
  158. <hr>
  159. <p>&nbsp;</p>
  160. </body>
  161. </html>
  162.  
  163.  
  164.  
Nov 2 '09 #1
Share this Question
Share on Google+
4 Replies


P: 1
I've used this code before. The page is building XML. The <link> tag is just a URL, not HTML so there is no target to add. Where the page opens (parent, new window, new tab) is up to the user or their browser settings. I guess you could duplicate the link the description of the item. In there you can use standard html and just add an href with a specific target attribute.
Nov 3 '09 #2

jhardman
Expert 2.5K+
P: 3,405
you could force the issue by opening a new page on the step before this.
Nov 3 '09 #3

P: 49
@jhardman
Would you mind expanding on this for me? What should i do to force it?
Nov 9 '09 #4

P: 1
You add the target blank in the ItemTemplate bit line 35:

so where you have this:
Expand|Select|Wrap|Line Numbers
  1. ItemTemplate = "<tr><td><strong>{DATE}</strong><br/><strong>{CATEGORY}<br/></strong><a href=" & """{LINK}""" & ">{TITLE}</a><BR>{DESCRIPTION}</td></tr>"
  2.  
you add in the a href part:
Expand|Select|Wrap|Line Numbers
  1. ItemTemplate = "<tr><td><strong>{DATE}</strong><br/><strong>{CATEGORY}<br/></strong><a href=" & """{LINK}""" & " target='_blank'>{TITLE}</a><BR>{DESCRIPTION}</td></tr>"
  2.  
I've just tried this myself and it seems to work.



Now I have a question about this same script: The feed I am adding doesn't have excerpts so they are showing up on the site with full entire entries. Is there anyway I can modify this script just to show the first few sentences/first paragraph - make the feed cut after a certain length and add ... or something?

Thanks
Nov 19 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.