I am new to programming in Javascript and this one has clearly ‘clean bowled’ me :(……..
The following code snippet highlights some text by searching for and modifying the respective text nodes. Text node searching is done by using a Jquery functionality:
window.addEventListener(“load”, highlightSummarySentences , false);
function highlightSummarySentences() {
var docName = thisPage;
var numSentences = getCookie(docName+"Num");
var linkSentenceNum = getCookie(docName + 'LinkingSentence');
for(var i=0; i<numSentences; i++) {
var matchMe = getCookie(docName+i);
try {
if (matchMe && i==(linkSentenceNum)) {
highlightText(matchMe, clickedSentenceColour);
}
else if(matchMe){
highlightText(matchMe, summarySentenceColour);
}
} catch (e) {;
}
}
}
The for loop runs once and highlights the appropriate text after which it exits and the page becomes completely white. The following error is seen in the error console:
Error: getCookie is not defined
but I guess its not getCookie. The script just refuses to recognize any function or variable after the above event. I have no idea what might be causing the script to behave this way. I am developing in firefox.
Please give me a hint! Let me know if I should paste more code of give more information.
Thanks,
Your description(page clears after 1st loop) sounds like you use somewhere
document.write().Do you? (could be in highlightText())
If yes: you can’t use write() after a document is loaded, write() will overwrite all contents, js too, so all functions defined somewhere doesn’t exist anymore.