Twitter widgets.js throws JavaScript error “Expected identifier” on IE8

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 21:23:13

问题


Anybody run into a JavaScript error when trying to run Twitter For Web widgets.js on Internet Explorer 8 (IE8)? If so, do you know how to fix this or how to handle it gracefully?

CODE Just adding this block of code, which loads the widgets.js file throws an error on IE8:

<script>
window.twttr = (function (d, s, id) {
  var t, js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src= "https://platform.twitter.com/widgets.js";
  fjs.parentNode.insertBefore(js, fjs);
  return window.twttr || (t = { _e: [], ready: function (f) { t._e.push(f) } });
}(document, "script", "twitter-wjs"));
</script>

I got this snippet at: https://dev.twitter.com/web/javascript/loading

ERROR in IE8

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E) Timestamp: Thu, 29 Jan 2015 00:54:28 UTC

Message: Script error Line: 0 Char: 0 Code: 0 URI: https://platform.twitter.com/widgets.js

That was not helpful, but in the Developer tool, under Script I get the following message:

(X) Expected identifier widgets.js, line 1 character 29036

I also investigated and found that Twitter stopped fully supporting IE7 last year (2014) and is stopping support for IE8 early in January 2015. I'm not sure if this is why their widgets.js causes an error or not, but I still need to figure out what the best way is to load this script without throwing an error on IE8. Thank you!


回答1:


Found the solution,

In widgets.js, there is a method which name is "delete" (line 364)

"delete": function(t) {
     var e = i(t),
     n = this.get(e.slice(0, -1));
     n && delete n[e.slice(-1)]
 },

and this method calling on line 1364

l.delete(["callbacks", t.callbackName])

delete is in Reserved Words list. So it causes "Expected identifier" error.

Firstly, take widgets.js to your own host.

js.src= "http://www.yourdomain.com/widgets.js";

change here with your domain.

After or before that step In widgets.js, have to change "delete" method name and caller line.




回答2:


Anyone tried this? How to Add Fat-Free Social Buttons to Your Pages http://www.sitepoint.com/social-media-button-links/

"The majority of social networks offer URL-based sharing buttons which add little weight to the page and do not require third-party JavaScript. They’re not as well publicized but they’re not difficult to use."



来源:https://stackoverflow.com/questions/28205278/twitter-widgets-js-throws-javascript-error-expected-identifier-on-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!