Saturday, January 17, 2009

Validate remote url using javascript

1. Read remote url.
var url ='<!--#echo var="REMOTE_HOST"-->';

2. Enter list of additional url
var additional_url = ["http://www.abc.com"];

3. Create a regular expression string.
var handleurl = additional_url.join("|");
handleurl = new RegExp(handleurl, "i");

4. Check condition whether remote url is in list
if (url.search(handleurl)!=-1)
alert("done")
else
alert("Unauthorized access");

No comments: