使用JSONP创建Blogger网站:无法在"DOMWindow"上执行"postMessage" [英] Using JSONP to Create Blogger Site: Getting Failed to execute 'postMessage' on 'DOMWindow'

查看:120
本文介绍了使用JSONP创建Blogger网站:无法在"DOMWindow"上执行"postMessage"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到:

无法在"DOMWindow"上执行"postMessage":提供的目标来源(" https://accounts.google. com ')与收件人窗口的来源不匹配(' https://www.blogger.com ").

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://accounts.google.com') does not match the recipient window's origin ('https://www.blogger.com').

使用我购买的模板运行博客网站时.该模板广泛使用JSONP并调用JQuery v1.11.0.

When running a blogger site using a template I purchased. The template makes extensive use of JSONP and calls JQuery v1.11.0.

以下是请求的示例:

if ( static_page_text === "[sitemap]" ) {
var postbody = $('.static_page .post-body');
$.ajax({
url: "/feeds/posts/default?alt=json-in-script",
type: 'get',
dataType: "jsonp",
success: function (dataZ) {
  var blogLabels = [];
  for (var t = 0; t < dataZ.feed.category.length; t++) {
    blogLabels.push(dataZ.feed.category[t].term);
  }
  var blogLabels = blogLabels.join('/');
  postbody.html('<div class="siteLabel"></div>');
  $('.static_page .post-body .siteLabel').text(blogLabels);
  var splabel = $(".siteLabel").text().split("/");
  var splabels="";
  for (get = 0; get < splabel.length; ++get) {
    splabels+= "<span>"+splabel[get]+"</span>";
  }
  $(".siteLabel").html(splabels);
  $('.siteLabel span').each(function() {
    var mapLabel = $(this);
    var mapLabel_text = $(this).text();
    $.ajax({
      url: "/feeds/posts/default/-/" + mapLabel_text + "?alt=json-in-script",
      type: 'get',
      dataType: "jsonp",
      success: function (data) {
        var posturl = "";
        var htmlcode = '<div class="mapp">';
        for (var i = 0; i < data.feed.entry.length; i++) {
          for (var j = 0; j < data.feed.entry[i].link.length; j++) {
            if (data.feed.entry[i].link[j].rel == "alternate") {
              posturl = data.feed.entry[i].link[j].href;
              break;
            }
          }
          var posttitle = data.feed.entry[i].title.$t;
          var get_date = data.feed.entry[i].published.$t,
              year = get_date.substring(0, 4),
              month = get_date.substring(5, 7),
              day = get_date.substring(8, 10),
              date = '<span class="day">' +  day.replace(/^0+/, '') + '</span><span class="month">' + text_month[parseInt(month, 10)] + ' </span><span class="year">' + year + '</span>';

          htmlcode += '<div class="mpost"><div class="map-date">' + date + '</div><h3 class="rcp-title"><a href="' + posturl + '">' + posttitle + '</a></h3></div>';
        }
        htmlcode += '</div>';
        mapLabel.replaceWith('<div class="maplabel"><h2>' + mapLabel_text + '<span class="butoo"><i class="fa fa-plus-circle"></i></span></h2>' + htmlcode + '</div>');
        $(document).on('click','.maplabel h2',function(){
          $(this).parent('.maplabel').addClass('active');
          $(this).find('.butoo .fa').removeClass('fa-plus-circle').addClass('fa-minus-circle');
        });
        $(document).on('click','.maplabel.active h2',function(){
          $(this).parent('.maplabel').removeClass('active');
          $(this).find('.butoo .fa').addClass('fa-plus-circle').removeClass('fa-minus-circle');
        });
      }
    });
  });
}
});
}

这是我得到的答复:

看起来好像没有设置标头,但我的理解是JSONP和JQuery处理该握手吗?

It doesn't look like the headers are getting set but my understanding is that JSONP and JQuery handle that handshake?

还有什么我需要做的吗?我希望能得到一些友好的指导.

Is there something else I need to be doing? I'd appreciate some friendly guidance.

先谢谢了.

推荐答案

由于博客读者身份设置为私人",因此供稿URL将不起作用.将其设置为公共"(在设置">基本">权限">博客读者"下)将解决此问题

As the blog readership is set to Private, the feed URLs won't work. Setting it to Public ( Under Settings > Basic > Permissions > Blog Readers) will resolve this problem

请参阅> https://support.google.com/blogger/answer /97933?hl = zh_CN

网站供稿不适用于私人博客.

Site feeds don't work with private blogs.

这篇关于使用JSONP创建Blogger网站:无法在"DOMWindow"上执行"postMessage"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆