944,110 Members | Top Members by Rank

Ad:
Sep 21st, 2006
0

Javascript causes page to crash

Expand Post »
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

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. document.getElementById && document.getElementById("LEFTNAV"))
  2. {//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]
<div align="justify">
<font class="navigation">
<a href="./networking.php" onMouseOver="displayNav( 'networking', '1' )" onMouseOut="restoreNav()">Networking</a> |
<a href="./hardsoft.php" onMouseOver="displayNav( 'hardwaresoftware', '1')" onMouseOut="restoreNav()">Hardware/Software</a> |
<a href="./viruses.php" onMouseOver="displayNav('virus', '1')" onMouseOut="restoreNav()">Viruses</a> |
<a href="./os.php" onMouseOver="displayNav('os', '1')" onMouseOut="restoreNav()">Operating Systems</a> |
<a href="./helpticket.php" onMouseOver="displayNav('webhelp', '1')" onMouseOut="restoreNav()">Web Based Help Tickets</a> |
<a href="./webdesign.php" onMouseOver="displayNav('webdes', '1')" onMouseOut="restoreNav()">Web Design</a> |
<a href="./training.php" onMouseOver="displayNav('training', '1')" onMouseOut="restoreNav()">Training</a>
</font>
<font id="LOGIN"><font class="login">
<a href="./login.php">Customer Login</a>
</font></font>
</div>[/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 = "<table align=\"left\" class=\"rpxtable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Wire(less) Networking</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Microsoft Servers</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Linux Servers</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">VLAN / VPN</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Cable Installation</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Network Hardware Setup</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Remote Support</a></font></td></tr><tr><td class=\"shader\"></td></tr></table>"
document.getElementById("navhead").innerHTML = "<font class=\"header\">Networking</font>"
break
case "hardwaresoftware":
document.getElementById("LEFTNAV").innerHTML = "<table align=\"left\" class=\"rpxtable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\" ><font class=\"navtext\"><a href=\"#\">Install/Removal</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Upgrades</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Hardware Cleaning</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Troubleshooting</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Data Backup</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Recovery Disks</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Drivers Disk</a></font></td></tr><tr><td class=\"shader\"></td></tr></table>"
document.getElementById("navhead").innerHTML = "<font class=\"header\">Hardware/Software</font>"
break
case "virus":
document.getElementById("LEFTNAV").innerHTML ="<table align=\"left\" class=\"rpxtable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Detection and Removal</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Preventative Software</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Adware / Spyware</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Preventative Maintanence</a></font></td></tr><tr><td class=\"shader\"></td></tr></table>"
document.getElementById("navhead").innerHTML = "<font class=\"header\">Viruses</font>"
break
case "os":
document.getElementById("LEFTNAV").innerHTML ="<table align=\"left\" class=\"rpxtable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Microsoft Windows</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Linux</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Macintosh</a></font></td></tr><tr><td class=\"shader\"></td></tr></table>"
document.getElementById("navhead").innerHTML = "<font class=\"header\">Operating Systems</font>"
break
case "webhelp":
document.getElementById("LEFTNAV").innerHTML ="<table align=\"left\" class=\"rpxtable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Web Based Help Tickets</a></font></td></tr><tr><td class=\"shader\"></td></tr></table>"
document.getElementById("navhead").innerHTML = "<font class=\"header\">Online Help Tickets</font>"
break
case "webdes":
document.getElementById("LEFTNAV").innerHTML ="<table align=\"left\" class=\"rpxtable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Logo Design</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Web Scripting</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Database Work</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Layouts</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Templates</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Shopping Carts</a></font></td></tr><tr><td class=\"shader\"></td></tr></table>"
document.getElementById("navhead").innerHTML = "<font class=\"header\">Web Design</font>"
break
case "training":document.getElementById("LEFTNAV").innerHTML ="<table align=\"left\" class=\"rpxtable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Windows OS</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Universal Linux/Unix Training</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Office Suites Training</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">PC Security</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Preventative Maintanence</a></font></td></tr><tr><td class=\"shader\"></td></tr><tr><td height=\"21px\" onMouseOver=\"this.className='yellowBG'\" onMouseOut=\"this.className='normal'\"><font class=\"navtext\"><a href=\"#\">Heald College Cisco Certification</a></font></td></tr><tr><td class=\"shader\"></td></tr></table>"
document.getElementById("navhead").innerHTML = "<font class=\"header\">Training</font>"
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]
Similar Threads
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Sep 21st, 2006
0

Re: Javascript causes page to crash

Have you tried using onload to keep the displayNav function from being read until after the page loads?
Team Colleague
Reputation Points: 92
Solved Threads: 21
Posting Pro in Training
FC Jamison is offline Offline
436 posts
since Jun 2004
Sep 21st, 2006
0

Re: Javascript causes page to crash

Click to Expand / Collapse  Quote originally posted by FC Jamison ...
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:
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Sep 21st, 2006
0

Re: Javascript causes page to crash

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
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: javascript image animation not working????
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Are U Sing Dreamweaver?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC