Forum Moderators: open
I'm very new to Javascript, and I'm having some issues where maybe someone could help me out. I'm trying to create a simple html page which has javascript embedded into it where it will get the URL string that the user enters and take the first subfolder and redirect the user appropriately. For instance, if I have the URL of http://example.com/helloworld, I would like to get the "helloworld" subdirectory and redirect that to some other URL. Can this be done? Thanks in advance for any help you all can provide.
Cheers,
Sheel
[edited by: DrDoc at 7:10 pm (utc) on Mar. 7, 2006]
Something like this, perhaps:
<script type="text/javascript">
var url = location.href.replace('/' + location.search + '$/', '');
url = url.replace(/^.*\/([^\/]*?)\/([^\/]*?\.[^\.]+?)?$/, '$1');
document.write(url);
</script>
var myURL, i;
myURL = document.URL;
document.writeln(myURL);
var myArray = myURL.split("/");
alert(myArray.length);
for(i = 3; i < myArray.length; i++)
{
document.writeln("<br> element is" + myArray[i] + "<BR>");
document.writeln(myArray.length)
if (myArray.length > 3)
{
document.writeln(myArray.length)
document.writeln("<br>" + myArray[3])
}
else
{
document.writeln("<br>lets do something")
}
}
So now what I want to do is that I would like to parse through each element in the array(which is the folder names), and verify that the folders exist. If it does, it will redirect the URL to the appropriate URL. So for instance, say I have a URL of http://example.com/sheel/working. I would like to check to see if the sheel folder exists, then from there redirect the working folder to another URL. I realize this is a somewhat complex issue, and thank anyone and everyone in advance for their help.
[edited by: DrDoc at 7:08 pm (utc) on Mar. 7, 2006]