返回主页时,小部件不会重新加载

时间:2016-02-07 16:08:24

标签: javascript jquery html ruby-on-rails twitter

我正在使用Twitter小部件在我的rails网站上加载主题标签搜索。当我第一次访问页面或单击重新加载时,窗口小部件正确加载。但是,如果我在整个网站中移动并返回上一页,它将不会加载小部件,而只是显示一个链接。即使我点击返回包含它的页面而不必重新加载页面,我是否可以进行任何更改以使窗口小部件加载?

我看到类似的问题已提出before,但我找不到可以提供帮助的答案。任何输入都会很受欢迎!

这是小部件代码:

<a class="twitter-timeline" data-dnt="true" href="https://twitter.com/hashtag/srag5" data-widget-id="695833566630932481">#srag5 Tweets</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

如果有帮助,这是我的application.html.erb:

<!DOCTYPE html>
<html>
<head>
  <link href='https://fonts.googleapis.com/css?family=Sura' rel='stylesheet' type='text/css'>
  <title><%= yield(:title) %> | RRH's World Language One To The World</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!--[if lt IE 9]>
      <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/r29/html5.min.js">
      </script>
    <![endif]-->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <%= favicon_link_tag 'favicon.ico' %>
</head>
<body>
  <%= render 'layouts/navbar.html.erb' %>

  <div class="container">
    <div class="jumbotron">
      <%= yield %>
    </div>   
  </div>
</body>
</html>

请参阅随附的图片enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

如Twitter社区forum所示,以及通过使用ajax的某人post,在小部件的末尾添加twitter.widgets.load()可以解决问题。

修改后的小部件将是:

<a class="twitter-timeline" data-dnt="true" href="https://twitter.com/hashtag/srag5" data-widget-id="695833566630932481">#srag5 Tweets</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs"); twttr.widgets.load();</script>