DOMContentLoaded and Safari
-
Comments:
- here.
Often, you will want some scripts to run when the page has loaded, even if the images on it haven’t. I wrote up some stuff about this under Best pre-onload. My full onDOMReady script looks like:
1 //Main Startup Code
2
3 function checkDOM(){
4 if (document.getElementById("footer")
5 || document.getElementById("credit"))
6 Startup();
7 else
8 setTimeout("checkDOM();",100);
9 }
10
11 if (document.addEventListener)
12 document.addEventListener("DOMContentLoaded", Startup, null);
13 else
14 setTimeout("checkDOM();",100);
However, Safari will not load pages that use this, since it has document.addEventListener, but does not create DOMContentLoaded events. So, I had to create a nasty little browser check rule:
1 if (document.addEventListener && (navigator.vendor != "Apple Computer, Inc."))
I’d rather not have to do things like this. Why not?