找回密码
 立即注册
搜索
查看: 45|回复: 0

[网络] 通过js代码禁止特定语言的访问

[复制链接]

3174

主题

652

回帖

1万

积分

版主

积分
17381
发表于 2025-9-8 08:51:25 | 显示全部楼层 |阅读模式
function checkLanguage() {
' R) D% E0 }. S    var userLang = navigator.language || navigator.userLanguage; // navigator.language for modern browsers, navigator.userLanguage for old IE  o& q, s2 ~: l; H$ T+ J; K
    var allowedLanguages = ['en-US', 'fr-FR']; // 允许的语言列表
' E/ ^- e9 Y% _9 Y% O7 o, C, A  \% N7 I6 |- w( g( r# _1 n
    if (!allowedLanguages.includes(userLang)) {" l" ^( V- U& C& G) ~9 @
        // 如果用户语言不在允许列表中,可以重定向到另一个页面或显示消息3 l5 A: y: g, d) j+ y
        window.location.href = 'https://your-restricted-page.com'; // 重定向到受限页面
4 ?! _1 a& K  V/ f; |, D        // 或者显示一个消息
. |: |6 l' S8 D, C2 l. S* q        // alert('Sorry, your language is not supported.');& e" d( c  ~5 A2 P, `( o# u( _
    } else {
* x; c2 Z  C3 k3 a- {* l. }7 E        // 允许访问8 o" D- m% p6 h) H2 A
        console.log('Language is allowed.');
. d6 p7 a$ W  Y. M+ h; u* n    }
  N" `4 U; [: v}7 j3 N  N6 o, ]  I3 B5 B

$ \/ e% z1 P; T1 O6 scheckLanguage();' d& X7 }7 X0 V  I

+ F* J+ P$ F5 e& J  i/ e6 j
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

捐款|存档|手机版|日常生活

© 2021-2026 THEDAILYLIVES.COM

快速回复 返回顶部 返回列表