User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 427,674 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,261 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 953 | Replies: 3
Reply
Join Date: Apr 2004
Location: Tracy
Posts: 744
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 32
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Javascript causes page to crash

  #1  
Sep 20th, 2006
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]
<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]
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2004
Location: Hemet, CA
Posts: 429
Reputation: FC Jamison is on a distinguished road 
Rep Power: 5
Solved Threads: 18
Colleague
FC Jamison's Avatar
FC Jamison FC Jamison is offline Offline
Posting Pro in Training

Re: Javascript causes page to crash

  #2  
Sep 20th, 2006
Have you tried using onload to keep the displayNav function from being read until after the page loads?
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 744
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 32
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Javascript causes page to crash

  #3  
Sep 21st, 2006
Originally Posted by FC Jamison View Post
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:
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 744
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 32
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Javascript causes page to crash

  #4  
Sep 21st, 2006
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
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 11:11 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC