Jump to content

Javascript Onload Issue with Firefox


ThePsion5

Recommended Posts

Hi,I'm creating a piece of javascript code designed to implement a simple tabbed web interface that uses a basic cookie to record the last tab visited. I'm familiar with programming languages in general, but I'm new to javascript and i've been encountering a perplexing error that seems to only occur with Firefox.Initially loading the page works well in IE and Firefox, but for some reason the code breaks upon some (but not all) subsequent loads in firefox. As far as I can tell, it has something to do with the onLoad function, specifically, it seems like Firefox does not call the onLoad function every time the refresh button is pressed, or only calls at certain intervals (like when i hit the refresh button 5 seconds after the last time i hit it. Is there something i'm missing? Thanks!-SeanEdit: The alert boxes are for debugging purposes.Here's my JavaScript code:

function checkCookie(){	//Retrieve the cookie    tabCookie = getCookie('tabCookie')	//If it exists    if (tabCookie!=null)    {  //Execute the display tabs function with the cookie's information  displayTabs(tabCookie)	}    else     {  //Otherwise, make the cookie        setCookie('tabCookie',tabCookie)  displayTabs("immenu")    }}

function displayTabs(activeTab){		var tabArray = new Array("immenu","semmenu","seamenu");	var thisTab    for (i = 0;i < tabArray.length; i++)    {        //Iterate through the tab array     thisTab = document.getElementById(tabArray[i])        //Set each tab to not display  alert(document.getElementById(tabArray[i]) + " should equal " + thisTab);     thisTab.style.display = "none";	}		if(activeTab == null)	{  //If the active tab is null, display a default  document.getElementById("immenu").style.display = "inline";	}	else	{  //Otherwise, display the appropriate tag        document.getElementById(activeTab).style.display = "inline";	}}

And Here's the relevant HTML:

<script src="../JavaScripts/tabCookie.js"></script></HEAD><BODY onload="checkCookie();">

Link to comment
Share on other sites

Hey, i wrote a simple test to see if firefox has problems with onload and it seems to be ok, the counter adds by one each time refresh is hit so i don't know if this helps you out any?--------------------------------------<head><script>function checkrefresh(){ var val=document.getElementById('one').value; val -=1; val +=2; document.getElementById('one').value=val;}</script></head><body onload="checkrefresh();"><input style="border:white" type="text" value="0" id="one" /></body>

Link to comment
Share on other sites

Well, I've done some tests and found that it only happens on my page, which means some part of my javaScript is preventing the page from reloading properly. I have no idea what, however.Is someone willing to take a look at my entire javascript code? It's not that long, but I'd feel like an arse posting the entire thing on here and making people read through it.

Link to comment
Share on other sites

Actually, I found out what the problem is.In my HTML file, I was using placeholders for images that referenced a non-existant file. When firefox tries to read these images, it apparently doesn't give up 2/3 times and although it loads the rest of the HTML, it never gets around to executing the javascript. I appreciate the attention though. Thanks! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...