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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question script not working; someone please assist!

    the code that i attached as a .txt file works for checking screen res., but not browser type. if you can discover the reason it does only half the job it's supposed to, please tell me!
    it's driving me buggy!!
    Attached Files Attached Files

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    you need to use braces ( { } ) when you write your if-else statements. they make things easier to read. try adding the braces. if that doesn't clear it up, then there's a more deeply rooted logic error.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    This should be the (somewhat) fixed code
    Code:
    <script language="JavaScript1.2">
    
    var browser_type=navigator.appName
    var browser_version=parseInt(navigator.appVersion)
    
    //if NS
    if (browser_type=="Netscape"&&browser_version>=5&&screen.width==800||screen.height==600)
    window.location.replace("800600netindex.html")
    else if (browser_type=="Netscape"&&browser_version>=5&&screen.width>=1024||screen.height>=768)
    window.location.replace("1024768netindex.html")
    else if (browser_type=="Netscape"&&browser_version>=5&&screen.width==640||screen.height==480)
    window.location.replace("640480netindex.html")
    //if IE 
    else if (browser_type=="Microsoft InternetExplorer"&&browser_version>=4&&screen.width==800||screen.height==600)
    window.location.replace("800600ieindex.html")
    else if (browser_type=="Microsoft InternetExplorer"&&browser_version>=4||screen.width==1024||screen.height==768)
    window.location.replace ("1024768ieindex.html")
    else if (browser_type=="Microsoft InternetExplorer"&&browser_version>=4&&screen.width==640||screen.height==480)
    window.location.replace("640480ieindex.html")
    //Default goto page (NOT NS 4+ and NOT IE 4+)
    else
    window.location="index.html"
    </script>
    Hope this helps,

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    166
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Presuming that the correct structure will be used, you either need to globally remove ||screen.height==600,768,480 - it's not needed as it's a given with the screen.width - or change the || to &&, or use brackets within the string.
    Right now, the criteria is:
    if it's the mentioned browser and version, OR if the height is (eg.) 600. The reason it's doing only half the job.

    As the previous posts mentioned, paste the script in the forum. Right now, it's a guess as to what the script reads as js code - such as a space between Internet and Explorer being required.

    Note. If you insert this code in the index.html, you may need to remove the last few lines:
    else
    window.location="index.html"
    as these would cause a non-mentioned browser to loop as the user is already on that page.

  • #5
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question re: script not working; someone please assist!

    this is the current code being used:

    Code:
    <script language="JavaScript1.2">
    
    
    var browser_type=navigator.appName
    var browser_version=parseInt(navigator.appVersion)
    
    //if NS 6
    
    else if (browser_type=="Netscape"&&browser_version>=5&&screen.width==800||screen.height==600)
    window.location.replace("800600netindex.html")
    else if (browser_type=="Netscape"&&browser_version>=5&&screen.width>=1024||screen.height==768)
    window.location.replace("1024768netindex.html")
    else if (browser_type=="Netscape"&&browser_version>=5&&screen.width==640||screen.height==480)
    window.location.replace("640480netindex.html")
    //if IE 
    if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4&&screen.width==800||screen.height==600)
    window.location.replace("800600ieindex.html")
    else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4&&screen.width==1024||screen.height==768)
    window.location.replace ("1024768ieindex.html")
    else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4&&screen.width==640||screen.height==480)
    window.location.replace("640480ieindex.html")
    //Default goto page (NOT NS 4+ and NOT IE 4+)
    else
    window.location="gorblimey.html"
    </script>

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Without reviewing anything else:

    //if NS 6

    else if (browser_type=="Netscape"&&browser_version>=5&&screen.width==800||screen.height==600)

    An else statement - without a corresponding if - is like saying:

    "...otherwise, do this" (???)

    ...instead of:

    "If this is true, do this, otherwise, do that"
    Last edited by adios; 08-27-2002 at 05:40 AM.

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    should be like this:

    if (browser_type=="Netscape"&&browser_version>=5&&(screen.width==800||screen.height==600))

    but this is better and clearer:

    Code:
    //if NS
    if (browser_type=="Netscape"&&browser_version>=5){
    	if (screen.width==800||screen.height==600)
    		window.location.replace("800600netindex.html");
    	else if (screen.width>=1024||screen.height>=768)
    		window.location.replace("1024768netindex.html");
    	else if (screen.width==640||screen.height==480)
    		window.location.replace("640480netindex.html");
    }
    //if IE 
    else if (browser_type=="Microsoft InternetExplorer"&&browser_version>=4){
    	if (screen.width==800||screen.height==600)
    		window.location.replace("800600ieindex.html");
    	else if (screen.width==1024||screen.height==768)
    		window.location.replace ("1024768ieindex.html");
    	else if (screen.width==640||screen.height==480)
    		window.location.replace("640480ieindex.html");
    }
    //Default goto page (NOT NS 4+ and NOT IE 4+)
    else
    window.location="index.html"
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    or this, a shorter one:

    Code:
    var suffix="";
    if (browser_type=="Netscape"&&browser_version>=5) suffix = "net";
    else if (browser_type=="Microsoft InternetExplorer"&&browser_version>=4) suffix = "ie";
    
    if (suffix){
    	if (screen.width==800||screen.height==600)
    		window.location.replace("800600"+suffix+"index.html");
    	else if (screen.width>=1024||screen.height>=768)
    		window.location.replace("1024768"+suffix+"index.html");
    	else if (screen.width==640||screen.height==480)
    		window.location.replace("640480"+suffix+"index.html");
    }
    else window.location="index.html"
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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