2015-10-18 18 views
4

不工作我已經包括使用this docs在我的web應用程序谷歌登入,但是當我嘗試從Safari瀏覽器加載網站在隱私模式下我總是得到以下錯誤控制檯登入谷歌在Safari隱私模式

QuotaExceededError: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota. 
setItem4187590794-idpiframe.js:19:293 
g4187590794-idpiframe.js:19:293 
Ea4187590794-idpiframe.js:30 
(funzione anonima)4187590794-idpiframe.js:33 
onreadystatechange4187590794-idpiframe.js:11:477 

我知道在私人模式下的Safari瀏覽器不允許在localStorage中寫入,但是沒有任何解決方法可以讓Google登錄在私人模式下也能正常工作?

感謝

回答

0

不要讓的localStorage/sessionStorage的setItem拋出錯誤在Safari隱私瀏覽模式

看一看這樣的: https://gist.github.com/philfreo/68ea3cd980d72383c951

// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem 
// throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem 
// to avoid the entire page breaking, without having to do a check at each usage of Storage. 
if (typeof localStorage === 'object') { 
    try { 
     localStorage.setItem('localStorage', 1); 
     localStorage.removeItem('localStorage'); 
    } catch (e) { 
     Storage.prototype._setItem = Storage.prototype.setItem; 
     Storage.prototype.setItem = function() {}; 
     alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.'); 
    } 
} 

Safari瀏覽器隱私瀏覽是衆所周知的原因這樣的問題。解決這個問題的最簡單方法是改變localStorage函數。

試試這個

function isLocalStorageNameSupported() 
{ 
    var testKey = 'theTestKey', storage = window.sessionStorage; 
    try 
    { 
     storage.setItem(testKey, '1'); 
     storage.removeItem(testKey); 
     return localStorageName in win && win[localStorageName]; 
    } 
    catch (error) 
    { 
     return false; 
    } 
} 

你可以找到一個詳細的文檔和其他在這裏的解決方案:https://github.com/marcuswestin/store.js/issues/42

+0

的問題是谷歌JS裏面,這不是正確地加載和谷歌登入不起作用。如果localStorage不可用,我解決了不加載JS的問題 – GUL

+0

@GUL如果您......您對Google Sign-In沒有使用Google JS API做了什麼?如果你在Git上有你的代碼,那很好。先謝謝你。 – JackW327

+0

對不起,但我不能顯示整個代碼,但我可以解釋我做了什麼。如果localStorage不可用,我不加載Google JS API。爲了測試localStorage是否可用,我只是嘗試寫一個值,如果它引發一個異常而不是不可用 – GUL