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开发者_JAVA百科://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.
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/";
}
});
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.
精彩评论