We have a few places where we include inline <script>
blocks which run code, wrapped by $(document).ready()
. Several of these blocks use methods dependent on other external scripts. During normal page execution this technique works fine, but when the user navigates away from the page before it's completely loaded, the $(document).ready()
event is triggered and IE is throwing "Object does not support this property or method"
errors left and right.
Through some testing I've found out that the window.beforeunload
event is triggered before any of the ready
events, so I'd like to be able to prevent the ready
events from being triggered at that point. Ideally I'd like to have a solution that generalizes so I don't have to modify all of the inline code.
If that's not possible would you suggest wrapping all of the inline code in try-catch
blocks, determining if all the external scripts have been loaded before executing the inline code, etc?