...

View Full Version : script not working; someone please assist!



ert3
08-26-2002, 05:39 AM
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!!

joh6nn
08-26-2002, 06:36 AM
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.

martin_narg
08-26-2002, 12:29 PM
This should be the (somewhat) fixed 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

PauletteB
08-26-2002, 07:33 PM
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.

ert3
08-27-2002, 05:30 AM
this is the current code being used:


<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>

adios
08-27-2002, 05:37 AM
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"

glenngv
08-27-2002, 07:11 AM
should be like this:

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

but this is better and clearer:



//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"

glenngv
08-27-2002, 07:19 AM
or this, a shorter one: :)



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"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum