2012年"未捕获的TypeError:无法在Safari和Chrome上调用方法'getPropertyValue'为null"

min*_*yer 5 javascript jquery disqus requirejs backbone.js

在我的公司,我们正在努力使用惊人的Disqus小部件提供良好的评论体验.

我们的网站完全基于AJAX,最常使用requirejs,jquery和backbone.

我们已经在我们需要的页面上添加了Disqus小部件.在页面更改期间,我们当然会破坏Disqus小部件所在的div,并再次实例化所有内容.

在每个浏览器上,旧的小部件都可以.问题发生在于激活了2012 2012年的小部件,在Safari和Chrome上没有出现错误"未捕获的TypeError:无法调用方法'postMessage'的null".Firefox非常棒.

这是涉及的代码:

define([
  'underscore',
  'backbone',
  'models/config',
  'models/book'
], function(_, Backbone, config) {

    App.Models.Disqus = Backbone.Model.extend({
        bookObj: null,

        initialize: function(options){
            console.log("discus.initialize()");
            var _this=this;

            _this.bookObj= new App.Models.Book({id: options.id});
            _this.bookObj.fetch({
                dataType: 'jsonp',
                success: function(model,response){
                    (typeof DISQUS == 'undefined')?_this.initDisqus():_this.resetDisqus();              }
            });

        },

        initDisqus: function(){
            console.log("discus.init()");
            disqus_shortname=config.get('DISQUS_ID');
            disqus_title = this.bookObj.get('content').title; 
            disqus_config = function (){
                // this.page.identifier = _this.id;
                // this.page.url = document.URL;
                this.language = config.get('LANG');
            };
            require(['http://'+disqus_shortname+'.disqus.com/embed.js'], function(){});
        },

        resetDisqus: function(){
            console.log("discus.reset()");
            var _this=this;
            DISQUS.reset({
                reload: true,
                config: function(){
                    this.page.identifier = _this.id;
                    this.page.url = document.URL;
                    this.page.title = _this.bookObj.get('content').title;
                    this.language = config.get('LANG');
                }
            });
        }

    });

    return App.Models.Disqus;
});
Run Code Online (Sandbox Code Playgroud)

如果您需要更多信息,请随时提出.

在此先感谢Giorgio

好的伙计们,用这种方式解决了:

define([
  'underscore',
  'backbone',
  'models/config',
  'models/book'
], function(_, Backbone, config) {

    App.Models.Disqus = Backbone.Model.extend({
        bookObj: null,

        initialize: function(options){
            console.log("discus.initialize()");
            var _this=this;
            _this.bookObj= new App.Models.Book({id: options.id});
            _this.bookObj.fetch({
                dataType: 'jsonp',
                success: function(model,response){
                    //(typeof DISQUS == 'undefined')?_this.initDisqus():_this.resetDisqus();

                    delete DISQUS;

                    disqus_shortname = config.get('DISQUS_ID');
                    disqus_identifier = _this.id;
                    disqus_url = document.URL;         
                    disqus_title = _this.bookObj.get('content').title;

                    (function() {
                        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
                        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
                    })();

                }
            });
        },
    });

    return App.Models.Disqus;
});
Run Code Online (Sandbox Code Playgroud)

Tyl*_*yes 1

正如DISQUS.reset 文档所述,您需要重置 Disqus 线程的标识符和 URL。这是通过文档中提供的两个变量完成的:this.page.identifierthis.page.url。现在您正在 Disqus 中重置页面标题和语言。请尝试重置标识符和 URL。