在我的公司,我們正在努力使用精彩的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;
});
嗨泰勒,我更新了源代碼,但仍然沒有結果。 – mindflayer
請注意,在所有瀏覽器中使用舊插件工作時,所有工作都可以在Firefox上正常運行。 – mindflayer
解決沒有DISQUS.reset。 – mindflayer