简体   繁体   English

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

[英]Show login screen If the user is not logged in | jQuery

I try to display Login Screen in the spesific URL ('ads/audience-insights') If the user is not logged in. but no luck. 如果用户未登录,则尝试在特殊的URL ('ads/audience-insights')显示“登录屏幕('ads/audience-insights')

Can you correct my code? 您可以更正我的代码吗? what's wrong? 怎么了?

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();
        }
    });
}

This code == user Not logged in yet.. 此代码==用户尚未登录。

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

You don't have to use chrome.storage or the callback function. 您不必使用chrome.storage或回调函数。

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

You also do not have to check if the user is on a specific page as the code will not execute if they are not on said page in the first place. 您也不必检查用户是否在特定页面上,因为如果用户不在该页面上,则代码将不会执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅当用户未登录时才显示登录屏幕 - Show login screen only if user is not logged in 如果用户在使用 react-navigation 打开应用程序时未登录,则显示登录屏幕 - Show login screen if user is not logged in when opening the app with react-navigation 如果未登录,则将用户从 JQuery 自动完成重定向到登录页面 - Redirect user to login page from JQuery autocomplete if not logged in jQuery PHP Ajax检查用户登录show modal - jQuery PHP Ajax Check User Logged in show modal Spartacus SSR 模式:在组件上应用 AuthGuard 后,虽然用户已经登录,但在刷新时会暂时显示登录屏幕 - Spartacus SSR mode :After Applying AuthGuard on Component , login screen is displayed momentarily on refresh though user is already logged in 如果用户已登录并且在所有其他情况下显示公共路由,如何重定向到 /dashboard 公共路由 /login 和 /register? - How to redirect to /dashboard public routes /login and /register if user is logged in and in all other cases show public routes? 用户登录后显示底部导航 - Show BottomNavigation once the user is logged JavaScript-显示用户是否登录到Facebook - javascript - show if user logged to facebook 未登录用户的“登录”值和已登录用户的“注销”值 - 'Login' value for non logged user and 'Log Out' value for logged in user 如果用户未登录,rails jquery弹出窗口 - rails jquery popup if user not logged in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM