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 375,231 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 2,217 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

Javascript breaks IE - please help.

Join Date: Jul 2006
Posts: 155
Reputation: tefflox is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Re: Javascript breaks IE - please help.

  #20  
Dec 13th, 2007
Now I'm really confused. The uri is throwing errors like fireworks, and the inner pages do the same (just somewhat slower) after the text engine makes the final character visible.

I'm hoping the solution is in the following lead. I can appreciate your impatience, earlier, because I had no idea that you were seeing what I am only now getting to... :-(

Originally Posted by hielo View Post
>>if you go back to alterText, you would realize that there are at most 23 letters. Hence you should not call alterText more than 23 times
because there is no letter with id 24. The largest you have is "L23".

Actually there are 24 letters on "listenlightpoetryjournal", but since you enclosed each of them in a span and the id's were enumerated starting with 0, the last letter has id="n23"

From your original code:
document.getElementById(letter++).style.color=genHex();
this would be problematic when letter increases beyond 23 because there is no (for example):
<span id="n24">?</span> where "?" could be any letter. letter is increased only once when the function alterText() is called, but the real problem is that your code never stopped calling alterText(). This is because setInterval() acts like an alarm clock. The first argument would be sort of the beep/tune that the clock will play, and the second argument would be time between beeps. If you don't shut off the alarm button, the alarm will go on forever [ assuming an atomic powered clock ]. This same principle is taking place here. The other two paragraps following the one I just explain basically describe how to shut-off the alarm clock

>>window.onload=function(){
timer[0]=setInterval("alterText();", 110);
timer[1]=setInterval("alter();", 100);
timer[3]=setInterval("alter();", 100);
}

In HTML you could do something like:
<body onload="beginProcess()">

You can avoid adding that to your HTML markup by doing the following:
function beginProcess()
{
...
}

window.onload=beginProcess;

Notice the missing parenthesis at the end of the last statement. That is because we are not calling the function. We are simply assigning it to the window object and will be invoked once the document finishes loading on the browser window.

If you notice, on my example, I just defined the function first, then I assigned it to window.onload.

On the code that I pasted on my previous code, it did both at once and didn't bother to give that function a name because I was only going to use once. At the time the page finished loading.

>>setTimeout("setInterval('alterText();', 90);", 2500);

Not sure what is meant by "bad practice".

This page explains both setTimeout and setInterval:
http://www.siteexperts.com/forums/vi...1&t=all&area=0

Just to clarify, as soon as the Javascript interpreter gets to that line, due to setTimeout, it will makes a "note" to itself, that in 2500 milliseconds later it needs to execute the following code:
setInterval('alterText();', 90)

Basically it delays its execution. Then when 2500 milliseconds have elapsed it executes setInterval once and that's it. In turn, setInterval executes, alterText() every 90 milliseconds repeatedly, forever.

If anything, that is the "bad practice". Basically you are consuming resources "forever" [ actually as long as the person is viewing your page].

>>The pages work in my browser (FF2 i686 linux (swiftox))

The original code you posted did not truly work on FF. You thought it was working because it was not halting browser execution every time it threw an error. IE was halting execution altogether. I know for a fact that FF was throwing errors because I have a built in debugger installed that is contantly monitoring any page that loads and clearly indicates any errors on the page. They were all related to the variable letter being incremented beyond 23.
Reply With Quote  
All times are GMT -4. The time now is 4:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC