は繰延を使用してmiken32の答えを少し改良版であることができます:約束を使用して
function whenNoTrackingProtection() {
if (!whenNoTrackingProtection.promise) {
var dfd = new $.Deferred();
whenNoTrackingProtection.promise = dfd.promise();
var time = Date.now();
$('<img/>')
.attr('src', '//apps.facebook.com/favicon.ico')
.on('load', dfd.resolve)
.on('error', function() {
if ((Date.now() - time) < 50) {
dfd.reject();
} else {
// the request took to long, it seams this is a real network error
dfd.resolve();
}
});
}
return whenNoTrackingProtection.promise;
}
かのjQueryなし
、:
function whenNoTrackingProtection() {
if (!whenNoTrackingProtection.promise) {
whenNoTrackingProtection.promise = new Promise(function(resolve, reject) {
var time = Date.now();
var img = new Image();
img.onload = resolve;
img.onerror = function() {
if ((Date.now() - time) < 50) {
reject();
} else {
// the request took to long, it seams this is a real network error
resolve();
}
};
img.src = '//apps.facebook.com/favicon.ico';
});
}
return whenNoTrackingProtection.promise;
}
"?ユーザーが追跡保護を使用している場合どのように私は検出することができます"トラッキング保護のポイントを見逃しているように思えますか? – TylerH
@タイラーH:あなたに、「あなたがアプリの重要な機能に欠けています - 通常のブラウジングモードを使用し、これが利用可能になる」などのようなものをユーザーに伝えたい場合はありません。 – PetrHejda
そうした追跡メッセージを避けることは、追跡保護/プライベートブラウジングの*ポイント*です。あなたは間接的に追跡されることは望ましくありません。あなたが私がどこにいるのか、私があなたのエリアにいるのかを知ることは望ましくありません。すべてのユーザーのために、ページの上部に「このサイトはクッキーを使用しています」バナーの1つを入れてください。 – TylerH