Most of the developer who working in MS platform will be used to the javascript window.attachEvent.
But maybe some of you don’t know that window.attachEvent is only working on IE7+ and Opera only. Your coding will hit an javascrpit error when running at IE 6 or any version of firefox.
To resolve this issue, you may need to modify your code as such:
Original Code:
window.attachEvent(“onload”, Page_load);
function Page_load(){
//function code
}
Modify code:
//set page event handlers
if (window.attachEvent) {
//IE and Opera
window.attachEvent(“onload”, Page_load);
} else if (window.addEventListener) {
// IE 6
window.addEventListener(“load”, Page_Unload, false);
} else {
//FireFox
document.addEventListener(“load”, Page_Unload, false);
}
function Page_load(){
//function code
}
More From david_cheong
- ISNULL, NULLIF MsSQL function
- Progress and Revolution
- WinRAR 3.80 Pro – Full and No Activation Needed
david_cheong Recommends
- Improved features in Windows 8 – Preview (Sathiya seelan)
- Small Woodturning – 5 Methods To Satisfaction in the Art and Craft (Abba Piano Tuning)
Popularity: 1% [?]
No related posts.






Comments
No Responses to “Attaching event in both MSIE and FF with Javascript”