Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    ush
    ush is offline
    New to the CF scene
    Join Date
    Apr 2003
    Location
    UK
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question analysing current URL using RegExp?

    Hello!

    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!

    Cheers

    ian.
    Attached Files Attached Files

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <script type="text/javascript">
    url = parent.location.href;
    if(url="http://www.thgrid.org.uk") {
    //code here
    }
    else {
    //code here
    }
    </script>

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Chris, a typo

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

  • #4
    ush
    ush is offline
    New to the CF scene
    Join Date
    Apr 2003
    Location
    UK
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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")

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Code:
    function testURL(url){
    // Do they have to use www.? If so use
        var
            reMain=/^http:\/\/www\.thegrid\.org\.uk/i,
    // Otherwise use
            reMain=/^http:\/\/(www\.)?thegrid\.org\.uk/i,
    //  Same goes for schools, 
            reSchool=/^http:\/\/www\.(\w+)\.herts\.org\.uk/i,
    // or
            reSchool=/^http:\/\/(www\.)?(\w+)\.herts\.org\.uk/i,
            sSchool;
        if(reMain.test(url)){
            // 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;
    }
    Last edited by liorean; 04-04-2003 at 07:50 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •