javascript 未捕获的参考错误:stLight 未定义(仅在 Chrome 中)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16139354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 03:23:57  来源:igfitidea点击:

Uncaught Reference Error: stLight is not defined (in Chrome only)

javascriptdjangogoogle-chromecross-domain

提问by Steve Bennett

My web page ends thus:

我的网页这样结束:

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

In FireFox and Safari, it behaves. In Chrome:

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

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

In other words, the code at w.sharethis.com/button/buttons.js has failed to execute, and hence, failed to define the stLight variable.

换句话说,w.sharethis.com/button/buttons.js 上的代码未能执行,因此未能定义 stLight 变量。

The page is part of a Django web application running on a remote server. Saving the generated HTML page locally, then viewing in Chrome, works correctly.

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

At this point I'm stuck. Something to do with the cross domain security model? There aren't any security exceptions.

在这一点上,我被困住了。与跨域安全模型有关吗?没有任何安全例外。

Some weird interaction with the other javascript files?

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

The static (generated) code is here. It won't run from Dropbox though.

静态(生成的)代码在这里。但它不会从 Dropbox 运行。

回答by Steve Bennett

Ok, think I may have found it: the site runs fine in Chrome's incognito(porn) mode. So I strongly suspect I've got some kind of extension that's interfering with it (like Do Not Track or something).

好吧,我想我可能已经找到了:该网站在 Chrome 的隐身()模式下运行良好。所以我强烈怀疑我有某种干扰它的扩展(比如不跟踪或其他东西)。

EDIT It's Collusion's "block known tracking sites" feature.

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

回答by Brett

In my case I found it to be a Chrome plugin called "Disconnect". Thanks to @SteveBennet for the clue.

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

回答by Bimal Dev

In my case I replaced

就我而言,我更换了

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

this by

这由

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

ShareThis

分享这个

回答by Hassan Ali Shahzad

In Magento stLight is not defined: This can be resolved by following: <script type="text/javascript"> window.onload = function(){ stLight.options({publisher: "ur-24e62f76-1f66-e3aa-1190-c533b729ca11", doNotHash: true, doNotCopy: true, hashAddressBar: false});} </script>

在 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>

Issue (I think) is js file http://w.sharethis.com/button/buttons.jsload after the script in which this function exists. so easiest solution in my mind is window.onload, may have other good solutions.

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

回答by Brad Werth

This can be caused by the Ghosteryextension, in addition to the extensions listed in the other answers.

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

回答by The Whiz of Oz

If you switched on the SSL on your site, you might want to try re-writing your ShareThis script:

如果您在您的站点上打开了 SSL,您可能想尝试重新编写您的 ShareThis 脚本:

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