【问题标题】:Uncaught Reference Error: stLight is not defined (in Chrome only)未捕获的参考错误:未定义 stLight(仅在 Chrome 中)
【发布时间】:2013-04-14 21:31:53
【问题描述】:

我的网页就这样结束了:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">var switchTo5x=false;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">
stLight.options({publisher: "ur-24e62f76-1f66-e3aa-1190-c533b729ca11", doNotHash: true, doNotCopy: true, hashAddressBar: false});
</script>
<script type="text/javascript" src="/static/bootstrap/js/bootstrap.js"></script>  
</body>
</html>

在 FireFox 和 Safari 中,它的行为。在 Chrome 中:

Uncaught ReferenceError: stLight is not defined nectar-tugg-art:229
(anonymous function)

换言之,w.sharethis.com/button/buttons.js 中的代码未能执行,因此未能定义 stLight 变量。

该页面是在远程服务器上运行的 Django Web 应用程序的一部分。将生成的 HTML 页面保存在本地,然后在 Chrome 中查看,可以正常工作。

此时我被卡住了。与跨域安全模型有关吗?没有任何安全例外。

与其他 javascript 文件的一些奇怪的交互?

静态(生成)代码是here。但它不会从 Dropbox 运行。

【问题讨论】:

  • 检查您的控制台,在此之前是否有任何错误
  • 不,没有。更多信息:制作buttons.js的本地副本并引用它,工作正常 - 没有错误。
  • 是否有可能在 sharethis.com 的脚本完成加载之前对调用 stLight 的脚本进行评估?
  • 遇到问题了,您的远程 html 在 SSL 上运行,但脚本来自非安全站点
  • 其实不是HTTPS。

标签: javascript django google-chrome cross-domain


【解决方案1】:

好的,我想我可能已经找到了:该网站在 Chrome 的 incognito(色情)模式下运行良好。所以我强烈怀疑我有某种扩展程序会干扰它(比如 Do Not Track 或其他东西)。

编辑 这是 Collusion 的“阻止已知跟踪站点”功能。

【讨论】:

  • “色情模式”成就了我的一天
【解决方案2】:

就我而言,我发现它是一个名为“断开连接”的 Chrome 插件。感谢@SteveBennet 提供线索。

【讨论】:

    【解决方案3】:

    在我的情况下,我替换了

    <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
    

    此人

    <script type="text/javascript" src="https://ws.sharethis.com/button/buttons.js"></script>
    

    ShareThis

    【讨论】:

      【解决方案4】:

      在 Magento stLight 中没有定义: 这可以通过以下方式解决: <script type="text/javascript"> window.onload = function(){ stLight.options({publisher: "ur-24e62f76-1f66-e3aa-1190-c533b729ca11", doNotHash: true, doNotCopy: true, hashAddressBar: false});} </script>

      问题(我认为)是js文件http://w.sharethis.com/button/buttons.js在该函数存在的脚本之后加载。所以我认为最简单的解决方案是 window.onload,可能还有其他好的解决方案。

      【讨论】:

        【解决方案5】:

        这可能是由Ghostery 扩展引起的,除了其他答案中列出的扩展。

        【讨论】:

          【解决方案6】:

          如果您在您的网站上启用了 SSL,您可能想尝试重写您的 ShareThis 脚本:

          <script type="text/javascript" src="https://ws.sharethis.com/button/buttons.js"></script>
          <script type="text/javascript">
            stLight.options({
              publisher:'12345',
            });
          </script>
          

          【讨论】:

            猜你喜欢
            • 2017-08-31
            • 2016-10-03
            • 2020-08-31
            • 1970-01-01
            • 2017-01-02
            • 2021-12-08
            • 1970-01-01
            • 2016-06-11
            • 2014-10-03
            相关资源
            最近更新 更多