   else
     callback()
 
-domDidLoad = ->
-  ready = 0
-  if doc.attachEvent and doc.readyState is "complete"
+unlistenDOMLoaded = ->
+  if doc.addEventListener
+    doc.removeEventListener DOMContentLoadedString, domDidLoad, false
+    _window.removeEventListener "load", domDidLoad, false
+  else
     doc.detachEvent onreadystatechangeString, domDidLoad
-    ready = 1
-  else if doc.addEventListener
-    doc.removeEventListener DOMContentLoadedString, domDidLoad, false
-    ready = 1
-  if ready and not domLoaded_
+    _window.detachEvent "onload", domDidLoad
+
+domDidLoad = (_event) ->
+  if doc.addEventListener or _event.type is "load" or doc.readyState is "complete"
+    unlistenDOMLoaded()
     domLoaded_ = true
     loadApplication() if shouldLoadApplication() or forceAppLoading_
 

    # document is already laoded, fire callback
    domDidLoad()
  else
    bindReady()


  return  unless appLoadingStatus_ is AppNotLoaded
  appLoadingStatus_ = LoadingApp
  loadScript applicationURL(applicationOptions), ->
    _window[privateNamespace]["init"] applicationOptions, ->
      appLoadingStatus_ = AppLoaded
      notifyObservers readyObservers_
      applicationDidLoad()
  `undefined`

api = _window[namespace]
if api and api['ready'] and api['load']
  console.error 'SublimeVideo loader has been installed more than once.'
else
  api = _window[namespace] = {}
  api["ready"] = (observer) ->
    if appLoadingStatus_ is AppLoaded
      observer()
