SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    England
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    long else statementwith non javascript inbetween

    Hello,

    Is it possible to have a javascript function which has a lot of code inbetween { and } , a lot of which is not JavaScript. What I have is a JavaScript which will direct the user to another site if their IP matches a given address. If it doesn't match the address then the page is displayed normally.

    The code was going to run something like :
    if IP = 0.0.0.0 redirect.

    If the IP didn't match then the page would be loaded as normal . However when the IP does match, the page sometimes shows, just for the few split seconds before it redirects.

    What i'd like to do (if possible) is have something like (this is pseudocode)

    <Script Language=Javascript)
    get IP address
    if(IP=0.0.0.0)
    {
    redirect
    }
    else
    { //start of else statment
    </script>

    Normal page code will be displayed eg forms.

    <script language=JavaScript>
    } //end of else statement
    </script>

    Would this scenario work?

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This sounds like something that should be done server-side - conditional inclusion of html.

    Do you have php or ssi support on your site?

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have SSI

    Code:
    var ip = '<!--#echo var="REMOTE_ADDR"-->', url;
    switch( ip )
    {
    	case '192.168.1.1' : url = "page1.htm"; break;
    	case '192.168.1.0' : url = "page2.htm"; break;
    	default : url = "home.htm";
    }
    top.location.replace( url );
    But I agree with Mike, this should be done completely server-side.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    England
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sadly this is run through Lotus Domino, and It seems quite limited.

    If it was PHP I could do it in 5 minutes!

    Thanks anyway.


Bookmarks

Posting Permissions

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