rrutkows
23 Sep 2008, 6:53 AM
Consider the following example
<html>
<head>
</head>
<body>
<script type="text/javascript" src="../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../ext-all-debug.js"></script>
<script type="text/javascript">
function test()
{
if (!Ext.isReady)
{
Ext.onReady(test);
return;
}
document.write("Ext.isReady");
}
setTimeout(test, 1000);//make sure test is executed after load/DOMContentLoaded events
</script>
</body>
</html>
The expected output is to see an "Ext.isReady" string.
On Fx 2.0.0.16 and Opera 9.52 no such string appears.
The suspected reason: The fireDocReady function of the EventManager has no chance to be executed if there were no onDocumentReady call before the load/DOMContentLoaded events. The example works in IE, because, for IE, the initDocReady function calls the fireDocReady directly.
And why does it works, if the scripts are included in the HEAD? My guess, by accident (there is no BODY yet, while the following is being executed, and hence the onReady(=onDocumentReady) is being called):
// Initialize doc classes
(function(){
var initExtCss = function(){
// find the body element
var bd = document.body || document.getElementsByTagName('body')[0];
if(!bd){ return false; }
//do something
return true;
}
if(!initExtCss()){
Ext.onReady(initExtCss);
}
})();
Now, why would one want to include the scripts in the BODY instead of the HEAD? Well, for example, if one uses the ASP.NET AJAX ScriptManager to load the scripts embedded in a dll.
Regards
Rudy
<html>
<head>
</head>
<body>
<script type="text/javascript" src="../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../ext-all-debug.js"></script>
<script type="text/javascript">
function test()
{
if (!Ext.isReady)
{
Ext.onReady(test);
return;
}
document.write("Ext.isReady");
}
setTimeout(test, 1000);//make sure test is executed after load/DOMContentLoaded events
</script>
</body>
</html>
The expected output is to see an "Ext.isReady" string.
On Fx 2.0.0.16 and Opera 9.52 no such string appears.
The suspected reason: The fireDocReady function of the EventManager has no chance to be executed if there were no onDocumentReady call before the load/DOMContentLoaded events. The example works in IE, because, for IE, the initDocReady function calls the fireDocReady directly.
And why does it works, if the scripts are included in the HEAD? My guess, by accident (there is no BODY yet, while the following is being executed, and hence the onReady(=onDocumentReady) is being called):
// Initialize doc classes
(function(){
var initExtCss = function(){
// find the body element
var bd = document.body || document.getElementsByTagName('body')[0];
if(!bd){ return false; }
//do something
return true;
}
if(!initExtCss()){
Ext.onReady(initExtCss);
}
})();
Now, why would one want to include the scripts in the BODY instead of the HEAD? Well, for example, if one uses the ASP.NET AJAX ScriptManager to load the scripts embedded in a dll.
Regards
Rudy