Log in

View Full Version : JavaScript in Headiclude loops?


colicab-d
09-15-2004, 08:37 PM
It would seem so as after inserting a bit of my own js to the end of the template the site refershes and refershes and refreshe sin an endless fashion.

Whats going wrong and cananyone comment on a place within the code that this js can be placed to allow the styleid to be set automatically upon a users visit, be they guest admin or whatever..??


var bbcount= 0;
while (bbcount<1)
{
if ((screen.width>=1024) && (screen.height>=768))
{
window.location="?styleid=22";
bbcount=bbcount+1;



} else {
window.location="?styleid=21";
bbcount=bbcount+1;
}

alert('We are experiencing a Javascript Issue and will be back shortly');
}


The alert is there for my own testing needs and for end users. WHat confuses me further is the fact Ive added a working counter yet this is being ignored and the js is executed time and time again.

I take it because the page reloads to set the new id its then re-executing this js over again :p

Would it be wise to set a cookie with a value of 1 or 0 denpendant on if the script is run?

That way i could use an if and see if the value is there and if not this would then be excecuted creating a cookie with the "has been run" value ?

colicab-d
09-15-2004, 08:54 PM
My full script now reads


<script language="javascript">

var bbcount= 0;
var aostyleon = getCookie("aostyleopt");
if (aostyleon != null)
{
}
else
{
while (bbcount<1)
{
if ((screen.width>=1024) && (screen.height>=768))
{
window.location="?styleid=22";
bbcount=bbcount+1;
setCookie("aostyleopt", "set");



} else {
window.location="?styleid=21";
bbcount=bbcount+1;
setCookie("aostyleopt", "set");
}

alert('We are experiencing a Javascript Issue and will be back shortly');
}
}
</script>

Natch
09-16-2004, 09:43 PM
window.location will act like a refresh - it is a command function that will reload your script every time is comes to that instance.

So it should loop with what you have...

You should be using javascript test is a styleid cookie is set, if not, then window.location to a script that does nothing but set this styleid cookie - then that script should come back to the test for the styleid cookie in the headinclude...

Get it ?