View Full Version : analysing current URL using RegExp?

04-04-2003, 09:00 AM

I have a custom 404 error page which handles errors from a number of web servers...

The main server is www.thegrid.org.uk.

The others are www.[schoolname].herts.sch.uk where [schoolname] is any one of 560+ schools hosted on our server.

What I'd like to do is analyse the current URL (using javascript with RegExp?) and use document.write on the 404 page to indicate to the user whether they have come from the main site or a school's site (since, frankly, most of them don't realise where they've come from) and give them different instructions on how to report the missing page

I have no server-side scripting with which to accomplish this, hence I'm resorting to javascript.

I've been supplied the attached .js file but it doesn't work - as a js novice I'm in need of some specialist help, hence I'm here. Is the attached file workable or is there a more elegant solution?

Anything you can help me with is greatly appreciated!



04-04-2003, 01:28 PM
<script type="text/javascript">
url = parent.location.href;
if(url="http://www.thgrid.org.uk") {
//code here
else {
//code here

Graeme Hackston
04-04-2003, 01:47 PM
Chris, a typo

if(url == "http://www.thgrid.org.uk") {

04-04-2003, 02:07 PM
Thanks, but will this only match the URL if it's exactly www.thegrid.org.uk - for example will it match www.thegrid.org.uk/foo/bar.html ?

I guess I want something that matches the string if it contains thegrid.org.uk (there are other thegrid.org.uk servers without "www")

04-04-2003, 06:47 PM
function testURL(url){
// Do they have to use www.? If so use
// Otherwise use
// Same goes for schools,
// or
// do things if from Main site here
}else if((sSchool=reSchool.exec(url))){
// do things if from School site here
// sSchool.pop() is the school name, if you want it.
return anythingYouLike;

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum