4

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!

jussjosh
  • 103
  • 2
  • 9

2 Answers2

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.

İlker Korkut
  • 3,129
  • 3
  • 30
  • 51
  • İlker, could you please share updated widget.js code which we have to place locally, it would be helpful. – Gourav Makhija Feb 11 '15 at 13:10
  • Gourav, just change the "delete" method's name with something different. – İlker Korkut Feb 11 '15 at 19:17
  • liker, I have changed but still it is not working :'( – Gourav Makhija Feb 19 '15 at 06:50
  • can you share widget.js on js fiddle, i can investigate , it may be updated by twitter. – İlker Korkut Feb 19 '15 at 16:28
  • liker, i have simply download js file from [twitter widget](platform.twitter.com/widgets.js) and change delete method name as suggested but still its not working and no error also. Have you seen this twitter community [post](https://twittercommunity.com/t/widgets-js-error-for-ie8-maybe-other-browsers/32211/2) – Gourav Makhija Feb 24 '15 at 07:01
0

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."

Harry Alffa
  • 61
  • 1
  • 5