首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于当前URL的if语句(未指定)

问基于当前URL的if语句(未指定)
EN

Stack Overflow用户
提问于 2017-01-21 20:54:29
回答 1查看 41关注 0票数 1

因此,我基本上是试图根据当前URL显示特定的RSS提要。在下面的解决方案中,我得到了一些东西,但我不想在变量中指定URL,而是检查当前的if it contains和URL,然后做/拉我的rss提要。

以下解决方案无法工作,因为我需要对多个URL进行多次检查。

代码语言:javascript
复制
jQuery(function($) { //  display rss feed based on current URL

// start conditions to display 3 feeds on different URLs

  var url = 'http://localhost:8888/';

  if (url.indexOf('8888') > -1) { 
      $(".feed1").rss("http://www.thehollywoodgossip.com/rss.xml",
      {
        limit: 17,
        entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
      })
      $(".feed2").rss("http://www.thehollywoodgossip.com/rss.xml",
      {
        limit: 17,
        entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
      })
      $(".feed3").rss("http://www.thehollywoodgossip.com/rss.xml",
      {
        limit: 17,
        entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
      })
  }
  if (url.indexOf('movies') > -1) { 
      $(".feed1").rss("http://www.thehollywoodgossip.com/rss.xml",
      {
        limit: 17,
        entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
      })
      $(".feed2").rss("http://www.thehollywoodgossip.com/rss.xml",
      {
        limit: 17,
        entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
      })
      $(".feed3").rss("http://www.thehollywoodgossip.com/rss.xml",
      {
        limit: 17,
        entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
      })
  }

.......

注意,提要URL将是不同的。这只是个样本。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-21 21:01:20

而不是

代码语言:javascript
复制
var url = 'http://localhost:8888/';

做

代码语言:javascript
复制
var url = window.location.href;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41784401

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档