26 HAZİRAN 2012, Salı
Nasıl eğer tarayıcı HTML5 Yerel Depolama desteği olmadığını tespit etmek için
Aşağıdaki kodu 7 ls exist
uyarılar:
if(window.localStorage) {
alert('ls exists');
} else {
alert('ls does not exist');
}
7 gerçekten yerel depolama desteği yok ama bu konuda hala uyarır. Belki de bu IE 7 tarayıcı ve belge modları: Internet Explorer 9 geliştirici aracını kullanarak Internet Explorer 9 kullanıyorum çünkü. Ya da belki bu sadece eğer LS destekleniyorsa test için yanlış bir yoldur. Doğru yolu nedir?
Ayrıca sadece birkaç HTML5 özelliklerini kullanarak ve büyük bir senaryo sadece bu birkaç şey için destek algılamak için değmez yükleme olduğum için Modernizr kullanmak istemiyorum.
CEVAP
26 HAZİRAN 2012, Salı
Modernizr kullanmak zorunda değilsiniz, ama onların yöntemi localStorage
desteklenen olup olmadığını tespit etmek için kullanabilirsiniz
modernizr at github
test for localStorage
// In FF4, if disabled, window.localStorage should === null.
// Normally, we could not test that directly and need to do a
// `('localStorage' in window) && ` test first because otherwise Firefox will
// throw bugzil.la/365772 if cookies are disabled
// Also in iOS5 & Safari Private Browsing mode, attempting to use localStorage.setItem
// will throw the exception:
// QUOTA_EXCEEDED_ERRROR DOM Exception 22.
// Peculiarly, getItem and removeItem calls do not throw.
// Because we are forced to try/catch this, we'll go aggressive.
// Just FWIW: IE8 Compat mode supports these features completely:
// www.quirksmode.org/dom/html5.html
// But IE8 doesn't support either with local files
Modernizr.addTest('localstorage', function() {
var mod = 'modernizr';
try {
localStorage.setItem(mod, mod);
localStorage.removeItem(mod);
return true;
} catch(e) {
return false;
}
});
mevcut kaynak kodu ile güncellendi
Bunu Paylaş:
Eğer belge yükledi olmadığını tespit e...
eğer belirli bir dosya olup olmadığını...
Nasıl bir tarayıcı Chrome jQuery kulla...
Nasıl JavaScript devre dışı olup olmad...
nasıl bir python değişken bir fonksiyo...