
Problem description:
I decided to test my website layout in different browsers so I've loaded it up in browsershots.org.
Result: Everywhere except on Internet Explorer 5.5 & 6 the site rendered correctly. On the mentioned versions a JavaScript error alert popped up followed by blank page. It appeared that Internet Explore 5.5 & 6 both fail to render a page when its DOM structure is changed by Javascript/AJAX methods residing in a element under the body tag. In that case Internet Explorer gives error: 'The Page cannot be Displayed' or 'Internet Explorer cannot open the Internet site http://... Operation aborted'
Here is the official statement on this issue from Microsoft: http://support.microsoft.com/kb/927917
Statistics:
When I looked at Google Analytics I've understood that around 70% from all users preferred Internet Explorer 35% of which using IE6. Because I wanted to help my IE6 users I ran the following solutions then tested again with browsershots.org:
Solutions:(chose what suits you)
- move the script at the end of your body tag or place it up in the head tag.
- load up your JavaScript code from a function called by window.onload
- do not load JavaScript code if your Internet Explorer version is < 7
- add the attribute defer="defer" after your script
Results: The stats showed over 30% increase in my website traffic. And that was a real success!
....
P.S. Sometimes same JavaScript code runs flawlessly under Firefox, but produces errors within Internet Explorer. So here are some common errors and ways of fixing them:
Expected identifier, string or number
array: var img= {width:100, height:100,}
Firefox runs without errors, IE - gives error.
Solution(remove the comma at the end, otherwise it actually instructs the interpreter to expect next element.):
var img= {width:100, height:100}
object Expected when working with previousSibling and nextSibling
var prev=el.nextSibling;
again Firefox goest without errors, in difference with Internet Explorer
Solution: always check whether the element exists or not:
if (el.nextSibling) {
//use the element
var prev=el.nextSibling;
}
...
Initial element check:
var el = document.getElementById("el_id");
if(el) {
//use the element
}
You can also try the free online JavaScript checker JSLint. by Nevyan Neykov
0 коментара:
Post a Comment