Internet Explorer X Firefox (a rant)
I have a list of articles that I published on the site, pretty much like the list of recent posts of this blog, and I used an XML file to store the links and descriptions of each article, like an RSS.
When the page loads, it reads the XML file and updates the list of articles automatically. This way I don't have to worry about updating every single html page.
Side note: The 50webs.com is a very good web hosting service, but so far it only hosts static pages, so I needed this workaround.
Anyway... Because I use the Visual Studio to create my pages and stuff it was pretty straightforward to build the script that loads the XML and produces the list of articles.
It took me only 7 lines of code. Yes, that's right. Only SEVEN lines of code. I tested it on IE and it worked just nice and easy.
Just in case you don't believe me, this is the code to update the list of articles on IE:
And then I opened the page on Firefox... BANG!
Nothing. Nada. Niente. Zip.
Just the "Reading..." message I had put to show while the items are being updated.
So once more I went back to the drawing board.
After searching the Firefox documentation, and working for three straight hours on it, I managed to make the same thing on Firefox.
Here is the code:
OK... I know... It IS a rant... But heck I'm quite frustrated for writing twice as many lines of code to do EXACTLY the same thing that was accomplished with a far less and easily understandable one.
I will not even try to explain WTF is going on with the Firefox code... If you want a detailed explanation leave a comment and I'll do my best to reply.
When the page loads, it reads the XML file and updates the list of articles automatically. This way I don't have to worry about updating every single html page.
Side note: The 50webs.com is a very good web hosting service, but so far it only hosts static pages, so I needed this workaround.
Anyway... Because I use the Visual Studio to create my pages and stuff it was pretty straightforward to build the script that loads the XML and produces the list of articles.
It took me only 7 lines of code. Yes, that's right. Only SEVEN lines of code. I tested it on IE and it worked just nice and easy.
Just in case you don't believe me, this is the code to update the list of articles on IE:
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');As you can see they are REALLY seven lines of code.
xmlXsl = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xmlDoc.load(atom_Articles);
xmlXsl.async = false;
xmlXsl.load(xslFile);
oAL.innerHTML = (xmlDoc.transformNode(xmlXsl));
And then I opened the page on Firefox... BANG!
Nothing. Nada. Niente. Zip.
Just the "Reading..." message I had put to show while the items are being updated.
So once more I went back to the drawing board.
After searching the Firefox documentation, and working for three straight hours on it, I managed to make the same thing on Firefox.
Here is the code:
function ffXslLoaded(e)SIXTEEN lines of code. More than twice the amount of code needed on IE.
{
var htmlDoc =
document.implementation.createDocument("", "", null);
var processor = new XSLTProcessor();
processor.importStylesheet(e.currentTarget);
e.currentTarget.DOC.AL.innerHTML = '';
e.currentTarget.DOC.AL.appendChild(
processor.transformToFragment(
e.currentTarget.DOC, document));
}
function ffDocLoaded(e)
{
var xmlXsl =
document.implementation.createDocument("", "", null);
xmlXsl.DOC = e.currentTarget;
xmlXsl.addEventListener("load", ffXslLoaded, false);
xmlXsl.load(e.currentTarget.XSL);
}
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.AL = oAL;
xmlDoc.XSL = xslFile;
xmlDoc.addEventListener("load", ffDocLoaded, false);
xmlDoc.load(atom_Articles);
OK... I know... It IS a rant... But heck I'm quite frustrated for writing twice as many lines of code to do EXACTLY the same thing that was accomplished with a far less and easily understandable one.
I will not even try to explain WTF is going on with the Firefox code... If you want a detailed explanation leave a comment and I'll do my best to reply.
0 Comments:
Post a Comment