Disqus 2012 "Uncaught TypeError: Cannot call getPropertyValue" null "method in Safari and Chrome

Here at my company, we are working hard to deliver a good comment using the experience of the amazing Disqus widget.

Our site is entirely AJAX based, using requirejs, jquery and backbone for most.

We have already added the Disqus widget to the pages where we need it. During the page change, we, of course, destroy the div where the Disqus widget lives, and we again create all the things.

Everything is fine with the old widgets in each browser. There is a problem with activating the Disqus 2012 widget, which does not appear with the error "Uncaught TypeError: cannot call the postMessage" null "method in Safari and Chrome. Firefox works fine.

Here is the code:

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

If you need more information, feel free to ask.

Thanks in advance, Giorgio

OK guys solved this way:

 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; }); 
+4
source share
2 answers

As indicated in the DISQUS.reset documentation , you need to reset the identifier and URL for the Disqus stream. This is done through two variables provided in the documentation: this.page.identifier and this.page.url . You are now reinstalling the page title and language in Disqus. Try resetting the id and URL instead.

+1
source

I also had this problem, but the solution above (removing DISQUS and reloading the script on the page) does not work in strict mode. Attempting to remove DISQUS results in the error "Delete unqualified identifier in strict mode."

I solved the problem by making sure that I never deleted the container Disqus is attached to, which I did when replacing a message with a message recently downloaded via ajax. It is strange that it worked in Firefox without this fix, but now it works everywhere.

0
source

Source: https://habr.com/ru/post/1440800/