2012-10-19 27 views
4

在我的公司,我們正在努力使用精彩的Disqus小部件提供良好的評論體驗。Disqus 2012「Uncaught TypeError:無法在Safari和Chrome上調用null的方法'getPropertyValue'

我們的網站完全基於AJAX,使用requirejs,jquery和骨幹最多。

我們已經在需要的頁面上添加了Disqus小部件。在頁面更改期間,我們當然會銷燬Disqus widget的div,我們再次實例化所有的東西。

在每個瀏覽器上,舊部件都可以正常工作。在Safari和Chrome上激活Disqus 2012的窗口小部件時出現問題,該窗口未顯示錯誤「Uncaught 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; 
}); 

如果您需要了解更多信息隨時問。

由於提前, 喬治

OK的傢伙,這樣解決:

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; 
}); 

回答

1

隨着DISQUS.reset documentation狀態,你需要重新設置標識和網址爲Disqus線程。這是通過文檔中提供的兩個變量完成的:this.page.identifierthis.page.url。現在,您正在重置Disqus中的頁面標題和語言。嘗試重置標識符和網址。

+0

嗨泰勒,我更新了源代碼,但仍然沒有結果。 – mindflayer

+0

請注意,在所有瀏覽器中使用舊插件工作時,所有工作都可以在Firefox上正常運行。 – mindflayer

+0

解決沒有DISQUS.reset。 – mindflayer

0

我也有這個問題,但上面的解決方案(刪除DISQUS並重新加載頁面上的腳本)不能在嚴格模式下工作。嘗試刪除DISQUS會導致錯誤「在嚴格模式下刪除非限定標識符」。

我解決了這個問題,確保我永遠不會刪除Disqus附加到的容器,當我通過ajax新加載的帖子替換帖子時,我正在做這個容器。奇怪的是,它沒有這個修復,它在Firefox的工作,但它現在無處不在。

相關問題