954,184 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Javascript causes page to crash

Hi all i will try to be as clear as possible!

I am currently working on a site for a customer at www.privacymaker.com/gcs/dev/ (where im developing it, the main site location is www.gerbercentral.com )

well here is the issue i am running into.

I have decided to go with mouseovers that change the innerHTML of an element, at first if you tried to mouse over the tags while the page was loading it would cause the page to abort loading and you would get an error message.

I decided that it may be due to me trying to reference an HTML element that had not been drawn yet.

so i inserted the line

document.getElementById && document.getElementById("LEFTNAV"))
{//continue code}


thinking that it would only execute the script if it could find the required element and only if the browser supported it...well i guess i was wrong because i am still getting crashes.


here is a copy of important HTML and the javascript file itself

[html]


Networking |
Hardware/Software |
Viruses |
Operating Systems |
Web Based Help Tickets |
Web Design |
Training


Customer Login

[/html]

this calls the functions and here are the functions

[html]
function displayNav( location, level )
{
var path;
//if the document has not loaded yet do NOT do this procedure
//will cause a browser crash due to elements needed not being renderd yet
if(document.getElementById && document.getElementById("LEFTNAV") && document.getElementById("navhead")){ //is required piece loaded?
stopDelay();
//check to see what level they are on
if(level == 1) {
//top level directory
path = "./";
path += location;
} else {
//level two
path = "../";
path += location;
}

switch(location)
{
case "networking":
document.getElementById("LEFTNAV").innerHTML = "Wire(less) NetworkingMicrosoft ServersLinux ServersVLAN / VPNCable InstallationNetwork Hardware SetupRemote Support"
document.getElementById("navhead").innerHTML = "Networking"
break
case "hardwaresoftware":
document.getElementById("LEFTNAV").innerHTML = "Install/RemovalUpgradesHardware CleaningTroubleshootingData BackupRecovery DisksDrivers Disk"
document.getElementById("navhead").innerHTML = "Hardware/Software"
break
case "virus":
document.getElementById("LEFTNAV").innerHTML ="Detection and RemovalPreventative SoftwareAdware / SpywarePreventative Maintanence"
document.getElementById("navhead").innerHTML = "Viruses"
break
case "os":
document.getElementById("LEFTNAV").innerHTML ="Microsoft WindowsLinuxMacintosh"
document.getElementById("navhead").innerHTML = "Operating Systems"
break
case "webhelp":
document.getElementById("LEFTNAV").innerHTML ="Web Based Help Tickets"
document.getElementById("navhead").innerHTML = "Online Help Tickets"
break
case "webdes":
document.getElementById("LEFTNAV").innerHTML ="Logo DesignWeb ScriptingDatabase WorkLayoutsTemplatesShopping Carts"
document.getElementById("navhead").innerHTML = "Web Design"
break
case "training":document.getElementById("LEFTNAV").innerHTML ="Windows OSUniversal Linux/Unix TrainingOffice Suites TrainingPC SecurityPreventative MaintanenceHeald College Cisco Certification"
document.getElementById("navhead").innerHTML = "Training"
break
default:
restoreNav();}
}

}
[/html]
and the other function
[html]
var timer;
function restoreNav(){
{
stopDelay();
timer = setTimeout("restore()", 1250);
delete timer;
}
function restore()
{
if(document.getElementById && document.getElementById("LEFTNAV")) { //only restor nav if they are using IE5+ or NS6 or Some version of FireFox
document.getElementById("LEFTNAV").innerHTML = currentSection;
document.getElementById("navhead").innerHTML = currentHead;
}
}
function stopDelay(){
//clear the timer
if(typeof timer == 'undefined'){
//nothing to stop
}
else{clearTimeout(timer);}
}
[/html]

Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

Have you tried using onload to keep the displayNav function from being read until after the page loads?

FC Jamison
Posting Pro in Training
Team Colleague
446 posts since Jun 2004
Reputation Points: 92
Solved Threads: 21
 
Have you tried using onload to keep the displayNav function from being read until after the page loads?



i tried using

if(document.onload)

but it didnt work...the mouse over just never seemed to start up!! :lol:

Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

w00t i figured out what my problem was and fixed it.

i needed to include the if(document.getElementById) statement in the restoreNav() funciton as it was also trying to reference the ID before it had been loaded.

problem solved :D

Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You