【问题标题】:Script not working with cloudflare ssl on blogger, but works when https is off脚本在博客上无法与 cloudflare ssl 一起使用,但在 https 关闭时可以使用
【发布时间】:2018-06-10 21:51:55
【问题描述】:

此脚本不适用于 Bloggger 自定义域 Cloudflare 免费 ssl 上的 https。它可以在 https 关闭时运行,但不适用于 https。

在首页显示文章描述的脚本。

$(document).ready(function($) {
  $('.post-summary').each(function() {
    var summary = $(this),
      getURL = summary.attr('data-url');
    $.get(getURL, function(data) {
        var text = $(data).find('.post-body').text().substr(0, 250);
        summary.html('<p>' + text + '...</p>');
      }, "html");
  });
});

上述脚本的 HTML:

<div class='resumo'>
  <span class='post-summary' expr:data-url='data:post.url'/>
</div>
<div style='clear: both;'/>
  <a class='read-more anchor-hover' expr:href='data:post.url'>Read More</a>
</div>

【问题讨论】:

    标签: javascript jquery http https blogger


    【解决方案1】:

    问题在于数据标签 - data:post.url。这将返回 post URL 的 HTTP 版本(当通过 jQuery 代码发出请求时,它会被浏览器阻止)。为确保 data:post.url 标记始终返回帖子 URL 的 HTTPS 版本,请在此标记末尾附加 .https。 HTML 代码将更改如下 -

    <div class='resumo'>
      <span class='post-summary' expr:data-url='data:post.url.https'/>
    </div>
    <div style='clear: both;'/>
      <a class='read-more anchor-hover' expr:href='data:post.url.https'>Read More</a>
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-17
      • 1970-01-01
      • 2018-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多