允许 URL 进入网站吗?

发布于 2024-12-05 05:35:35 字数 458 浏览 0 评论 0原文

我需要在页面加载之前允许访问几个 URL,其余 URL 将被重定向。

expample: If user trying to access these urls they will be allowed and 
   other urls will be redirected to google.com (example)

http://mysite.com/site/Dept/IT
http://mysite.com/site/Dept/IT/ITWS
http://mysite.com/site/dept/ce
http://mysite.com/site/dept/mkt
http://mysite.com/site/teams/dgt
http://mysite.com/site/teams/mm

在 jQuery 中如何做到这一点?为 URL 创建 arraylist 并检查 arraylist 并允许它们。

I have couple of URLs that I need to allow to access before page load and remaining URLs will be redirected.

expample: If user trying to access these urls they will be allowed and 
   other urls will be redirected to google.com (example)

http://mysite.com/site/Dept/IT
http://mysite.com/site/Dept/IT/ITWS
http://mysite.com/site/dept/ce
http://mysite.com/site/dept/mkt
http://mysite.com/site/teams/dgt
http://mysite.com/site/teams/mm

How can do this in jQuery? Making arraylist for URL and check against arraylist and allow them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我们的影子 2024-12-12 05:35:35

您可以在每个页面上加载 Javascript 片段,如果当前页面的 url 与其中任何一个都不匹配,它将重定向用户。

$(document).ready(function() {
    var urls = ["http://mysite.com/site/Dept/IT",
              "http://mysite.com/site/Dept/IT/ITWS",
              "http://mysite.com/site/dept/ce",
              "http://mysite.com/site/dept/mkt",
              "http://mysite.com/site/teams/dgt",
              "http://mysite.com/site/teams/mm"];
    if ($.inArray(document.location.href, urls) == -1) {
      window.location = "http://www.google.com/";
    }
});

You can load Javascript snippet on every page and it will redirect the user if the current page's url doesn't match any of these.

$(document).ready(function() {
    var urls = ["http://mysite.com/site/Dept/IT",
              "http://mysite.com/site/Dept/IT/ITWS",
              "http://mysite.com/site/dept/ce",
              "http://mysite.com/site/dept/mkt",
              "http://mysite.com/site/teams/dgt",
              "http://mysite.com/site/teams/mm"];
    if ($.inArray(document.location.href, urls) == -1) {
      window.location = "http://www.google.com/";
    }
});
雪花飘飘的天空 2024-12-12 05:35:35

将此用于外部 URL。

$(document).ready(function() {
    $('a').click(function() {
        if (!$(this).attr("href").match("^http://yoursite.com.*$"))
        {
            if (!confirm("Do you realy want to leave this site?"))
            {
                return false;
            }
        }
    });
});

如果您确实想拒绝服务器上的特殊 URL,我强烈建议您这样做它在服务器端。

Use this for external URL's.

$(document).ready(function() {
    $('a').click(function() {
        if (!$(this).attr("href").match("^http://yoursite.com.*$"))
        {
            if (!confirm("Do you realy want to leave this site?"))
            {
                return false;
            }
        }
    });
});

If you realy want to reject special URL's on your server I would realy suggest you to do it serverside.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文