IE JavaScript woes
October 19, 2008 12:28 PM
Subscribe
I'm trying to come up with a generalized comic viewer using just JavaScript. I have a solution that works in nearly all browsers, but fails miserably in Internet Explorer (several versions). I don't have easy access to a Windows machine, and wonder if anyone could help me figure out what I'm doing wrong (specifically for IE).
posted by jpburns to computers & internet (7 comments total)
2 users marked this as a favorite
It looks like Firefox and Safari are doing you a favor by enforcing execution in order of mention, download the file first because you use its script tag first, but this isn't by any means guaranteed. IE adopts the (also reasonable) method of just executing the current page first before pulling in external resources.
You have a few choices in resolving this:
First, and easiest, but arguably less professional is to just put the contents of comicScript.js inline in the html document at the appropriate place, which ensures the functions will always be defined at the proper time in either interpretation scheme.
Second, which requires some minor changes to your code but which provides a cleaner base on which to expand the script, if that's a concern:
function copyright(){var copyright="<p class='copyright'>Copyright © 2008 by James Burns, All rights reserved.</p>";
document.write (copyright);
InnerHTML (easier)
function copyright(){document.getElementByID('copyright').innerHTML='blah blah James Burns etc';
}
or DOM (better)
function copyright(){document.getElementByID('copyright').appendChild(document.createTextNode('blah blah James Burns etc';
}
Both of these require you to add <p id="copyright" /> (it should be an ID and not a class anyway since there's only one) in your document to place the text in the appropriate place, because ...
All of the inline JavaScript you have in the html file now would become something like:
window.onload = function() {checkIt(); /* Note: give me a better name plz */
headerTitle();
/* etc... */
copyright();
}
posted by moift at 1:47 PM on October 19, 2008 [2 favorites has favorites]