我在我的页面上添加了一个 Twitter 按钮,使用的代码来自 https://about.twitter.com/resources/buttons
一个非常基本的实现如下所示
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</body>
</html>
在所有浏览器中都能完美运行,但 IE8 除外,它会触发错误:SCRIPT1010:预期标识符 文件:widgets.js,行:1,列:29036
在文件 https://platform.twitter.com/widgets.js
我不明白我的实现怎么可能是错误的。有谁知道或者这真的是 Twitter 代码中的 IE8 错误吗?
最佳答案
根据Twitter widgets.js throws JavaScript error "Expected identifier" on IE8 ,Twitter 于 2015 年 1 月停止支持 IE8。
因此,我的“解决方案”是使用条件注释 <!--[if gt IE 8]><!-->
TWITTER CODE HERE <!--<![endif]-->
在 IE8 及更低版本中禁用推文按钮。
关于javascript - Twitter 按钮在 IE8 中导致 JS 错误(预期标识符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28178051/