Problem:
Certain Flash ads served by Google's Doubleclick introduce major memory leaks in IE, especially IE6, causing setTimeout and setInterval Javascript function to freeze and the browser window to hang.
The problematic Flash ads include two Javascripts files:
MotifExternalScript_xx_xx.js
globalTemplate_xx_xx.js
The bug seems to be in globalTemplate_xx_xx.js. We suspect that a setTimeout function is calling a closure in which DOM manipulation is occuring; a condition that makes memory leak in IE.
Solution:
Remove the ads from your page.
Thursday, September 11, 2008
Monday, July 14, 2008
domready event is buggy in IE
Problem:
IE intermittently throws an "Operation Aborted" alert when "domready" event is used and then crashes.
Solution:
Evidently, IE throws the "domready" event before the DOM is actually ready. Consequently, if the function called by the "domready" event does DOM manipulation, IE will panic since DOM isn't ready yet and throws an error.
It's recommended to always use the window "load" event in IE. If you're using YUI, it's also better not to use onAvailable/onContentReady since they are triggered when "domready" event is triggered.
IE intermittently throws an "Operation Aborted" alert when "domready" event is used and then crashes.
Solution:
Evidently, IE throws the "domready" event before the DOM is actually ready. Consequently, if the function called by the "domready" event does DOM manipulation, IE will panic since DOM isn't ready yet and throws an error.
It's recommended to always use the window "load" event in IE. If you're using YUI, it's also better not to use onAvailable/onContentReady since they are triggered when "domready" event is triggered.
Wednesday, May 28, 2008
Dynamically generated JavaScript files should have proper content-type header
Problem:
IE6 throws runtime errors on an error-free JavaScript file generated on the backend using JSP, PHP, ...etc.
Solution:
These runtime errors are due to IE6's inability to parse the file properly. Define the content-type of the document and set it to text/javascript. This will properly format the document and will remove any runtime errors thrown in IE6.
IE6 throws runtime errors on an error-free JavaScript file generated on the backend using JSP, PHP, ...etc.
Solution:
These runtime errors are due to IE6's inability to parse the file properly. Define the content-type of the document and set it to text/javascript. This will properly format the document and will remove any runtime errors thrown in IE6.
Check for extended properties inside for..in loops
Problem:
Running a for..in loop on an object returns all enumerated properties of that object, including any methods/properties added using the prototype property. In the age of ubiquitous JavaScript libraries such as Prototype that does extend built-in objects, not accounting for those extended properties could break your code.
Solution:
it's essential to check for those extended methods and properties whenever the for..in loop is used. This is done by using the hasOwnProperty() Object method.
Running a for..in loop on an object returns all enumerated properties of that object, including any methods/properties added using the prototype property. In the age of ubiquitous JavaScript libraries such as Prototype that does extend built-in objects, not accounting for those extended properties could break your code.
Solution:
it's essential to check for those extended methods and properties whenever the for..in loop is used. This is done by using the hasOwnProperty() Object method.
for (var elem in FunObject) {
if (FunObject.hasOwnProperty()) {
// proceed with code
}
}
Labels:
built-in objects,
defensive programming,
javascript,
loops,
prototype
Check availibility of user-defined objects before you using them
Problem:
Oftentimes, programmers take the existence of user-defined variables, properties and objects for granted, which in turn results into unstable code that works when those objects exist and fails when they don't.
Solution:
Always check the existence of the following objects before manipulating them:
Oftentimes, programmers take the existence of user-defined variables, properties and objects for granted, which in turn results into unstable code that works when those objects exist and fails when they don't.
Solution:
Always check the existence of the following objects before manipulating them:
- DOM objects
var elem_to_test = document.getElementById('ad-unit');
if (elem_to_test) {
// proceed with code
} - Global JavaScript variable/object
if (typeof YAHOO != 'undefined') {
// proceed with code
}
OR
if (window.YAHOO) {
// proceed with code
} - Object property
if (window.obj && obj.property) {
// proceed with code
}
Subscribe to:
Posts (Atom)