Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading what's in address box

Status
Not open for further replies.

Chomauk

Programmer
Jun 8, 2001
130
I want to be able to read and manipulate the text in the address box because if someone enters my URL with some capital letters it won't work. I want to be able to automatically change or at least read the text correctly and display the desired page.

Thanks.

If you're going through hell, keep going.
--Sir Winston Churchill (1874 - 1965)
 
I'm assuming that you mean capital letters in the parameters at the end of the URL will cause site failure. If you have the ability to change the code, then I would recommend that you extend it to allow for such capitalization gaffes. This would allow you to grab the information you want when the user arrives and never have to redirect.

However, that is not your question.

To get the address, in your JavaScript, grab document.location.href. This is the URL from the address box.

'hope that helps.

--Dave
 
You won't be able to fix it with Javascript. Javascript lives at a particular URL, and the problem is that the users are typing in the wrong URL in the first place.

You may be able to do something about it server-side. Assuming you're using Apache and are able to configure it, you can use [tt]mod_rewrite[/tt] to rewrite URLs on the fly - changing all upper- to lower- case, for example. A quick google came up with this article, you should be able to find others.

A custom 404 page may help your visitors to find their way too.

-- Chris Hunt
 
Yeah, that's why I assumed his problem was at the end of the URL (?param1=val1&param2=VAL2).

Obviously, Chomauk, if a user can't actually get to your page in the first place, then there's no way to know that there's even a problem in the user's URL that needs fixing.

If all you're worried about is an all-CAPS or all-lower-case address, then you can put pages at both locations (i.e., at and and immediately redirect to the location you want (without having to grab the address):

Code:
<html>
<head>
<script>
this.location = "[URL unfurl="true"]http://www.yourdomain.com/Page1.html";[/URL]
</script>
</head>
</html>

Beyond that, if a user is typing in (for example): "PaGe1.hTmL", then they don't really want to find your page. They're just goofing around.

--Dave
 
You could also use the toUpperCase() function, and then do your testing and processing based upon that.

var the_string = "a";

if (the_string.toUpperCase() == "A") {
alert("your string has a valid value.");
} else {
alert("your string has an invalid value.");
}

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
Thanks all. I'll try and let you know.

If you're going through hell, keep going.
--Sir Winston Churchill (1874 - 1965)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top