显示登录屏幕如果用户未登录| jQuery的

时间:2018-01-20 04:20:45

标签: javascript jquery redirect window.location

我尝试在特定网址('ads/audience-insights')中显示登录屏幕如果用户未登录但没有运气。

你能纠正我的代码吗?什么错了?

if (window.location.href.indexOf('ads/audience-insights') != -1) {
    chrome.storage.local.get("cnt9", function(result) {
        if (result.cnt9 == null || result.cnt9 == -1 || result.cnt9 >= 40) {
            // show login screen
            showLoginScreen();
        }
    });
}

此代码==用户尚未登录..

  

result.cnt9 == null || result.cnt9 == -1 || result.cnt9 >= 40

1 个答案:

答案 0 :(得分:0)

您不必使用chrome.storage或回调函数。

if (typeof(Storage) !== "undefined") {
  var a = localStorage.cnt9;
  if (a == null || a == -1 || a >= 40)
    alert("Not Logged In!");
}

您也不必检查用户是否在特定页面上,因为如果代码首先不在该页面上,则代码将不会执行。

相关问题