javascript Firefox 阻止 Facebook Js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33855626/
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
Firefox blocking Facebook Js
提问by Peter
with upgrade of Firefox to 42.0 I got some strange behavior..
随着 Firefox 升级到 42.0,我得到了一些奇怪的行为..
I'm calling FB.init method like this:
我像这样调用 FB.init 方法:
FB.init({
appId: '{$appid}',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
But in Firefox it gets blocked, I get warning:
但是在 Firefox 中它被阻止了,我收到警告:
The resource at "https://connect.facebook.net/en_US/all.js" was blocked because tracking protection is enabled.
由于启用了跟踪保护,“ https://connect.facebook.net/en_US/all.js”上的资源被阻止。
This is default behavior, I didn't set up any additional security or whatever..
这是默认行为,我没有设置任何额外的安全性或其他任何..
What to do?
该怎么办?
EDIT - after help and googling, this is a little bigger problem:
编辑 - 在帮助和谷歌搜索之后,这是一个更大的问题:
Turns out Firefox's Do Not Track and tracking protectionare two separate things:
事实证明 Firefox 的不跟踪和跟踪保护是两个独立的东西:
Do Not Trackis enabled in Preferences/Options > Privacy > "Tell sites that I do not want to be tracked". Enabling sends the DNT header but it does not block any requests.
不跟踪在首选项/选项> 隐私>“告诉网站我不想被跟踪”中启用。启用会发送 DNT 标头,但不会阻止任何请求。
Tracking Protectionis enabled in about:config > privacy.trackingprotection.enabled. Enabling does not send the DNT header, but does block requests based on Disconnect's blocklist. So detecting 2 isn't as easy as checking navigator.doNotTrack, because that property is only set for 1.
跟踪保护在 about:config > privacy.trackingprotection.enabled 中启用。启用不会发送 DNT 标头,但会根据 Disconnect 的阻止列表阻止请求。因此检测 2 并不像检查 navigator.doNotTrack 那样容易,因为该属性仅设置为 1。
Solution (temporarily) - try to do FB.init, if error do some alert..
解决方案(临时) - 尝试做 FB.init,如果错误做一些警报..
try {
FB.init({
appId: '{$appid}',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
}catch(err) {
alert('Some info for the user...');
}
Does anyone have better solution?
有没有人有更好的解决方案?
采纳答案by bodzin
From the client side, you can't. This is security policy Firefox. You can read about this issue in thread: https://bugzilla.mozilla.org/show_bug.cgi?id=1226498
从客户端,你不能。这是 Firefox 的安全策略。您可以在线程中阅读有关此问题的信息:https: //bugzilla.mozilla.org/show_bug.cgi?id=1226498
回答by luschn
A simple google search leads to this page: https://developer.mozilla.org/en-US/Firefox/Privacy/Tracking_Protection
一个简单的谷歌搜索导致这个页面:https: //developer.mozilla.org/en-US/Firefox/Privacy/Tracking_Protection
You should be able to deactivate that feature right where the message appears, or via about:config
. It should actually be deactivated by default afaik.
您应该能够在消息出现的地方或通过 停用该功能about:config
。它实际上应该在默认情况下被停用 afaik。
回答by joakimcs
A way to go about it is checking whether the FB object exists after all script resources have been loaded. In this way we are covered regardless of what caused the script load failure:
一种方法是在加载所有脚本资源后检查 FB 对象是否存在。通过这种方式,无论是什么导致脚本加载失败,我们都可以得到覆盖:
$(window).on("load", function() {
// If Facebook SDK failed to load ...
if (typeof FB === "undefined") {
// ... then change interface/set global variable to handle missing FB
}
});