| Page 1 of 1 | [ 7 posts ] |
|
Hi,
We are facing some issues when using YUI loader utility to load the scripts dynamically. I also noticed that YUI Get utility can also be used for loading the scripts. I tried experimenting with both YUI Loader and YUI Get utility. What I observed is the utility works well only in Firefox but not in IE. I am using IE 7. I spent more time debugging to see if something went wrong on my side but then I realized that the behavior is different between the 2 browsers. Is this a known issue? Are there any other restrictions that we should know off wrt browsers? Also, I observed that when using Get utility, I am using onSucess handler to create some javascript instances and then send it across as the return value in my JS api. I see that before the return statement if I have an alert statement, the code seem to be working. If not it is not working. This seems wierd to me. Is it because of some timing issue ??? Could it be that the script did not load completely and that is the reason why the api didn't work ??? and with the alert it completed downloading the script and the api worked as expected? Could you please clarify these issues? Thanks, Usha |
|
Can you post some sample code? As far as I know, the YUI Loader uses the get utility under the covers, so the behavior of one should derive from the other.
|
|
Hi Nick,
Thanks for your response. Here is my code... external = (function() { return { getJS : function() { var Y = YUI(); var obj1= new Object(); var obj2 = new Object(); var objList = new Array(); var url = "abc.js"; var tobj = Y.Get.script(url, { onSuccess: function(o) { obj1.helloworld = function(){return sayhello();}; obj2.helloworld = function(){return sayhello();}; objList[0] = obj1; objList[1] = obj2; }, context:Y } ); alert("file loaded"); return objList; } }; })(); I see the same behavior with both Loader and Get. My functionality does not work in IE. Again I am using IE 7. Thanks much, Usha |
|
HI,
Can some one pls answer my question? Thanks, Usha |
|
I suspect that this has to do with minor differences in the way the two browsers handle script insertion and caching. Your real problem is that you're going against the grain of how YUI wants to do things; Both the Loader and the Get utility are asynchronous*, so they'll return a value before they have completed executing. At some point after calling the method, the success callback you've given will execute. This is where you want your processing logic.
Try something like this: Code: YUI().use(function(Y) { var external = { getJS: function(success) { var scriptUrl = 'abc.js'; Y.Get.script(scriptUrl, { onSuccess: success }); } }; // later external.getJS(function() { // called when the script "abc.js" is successfully loaded // we can now use methods exposed by abc.js // var a = ABC.getA(), b = ABC.getB(); }); }) |
|
HI Nick,
I tried the code but still it works only with few alerts...Simulating sync behavior still does not help. I will try again exploring diff options. But pls let me know why the behavior is this way? Thanks, Usha |
|
I don't think it's possible to load an additional javascript file synchronously; I haven't seen a utility out there that does it, and I can't think of a way to do it without blocking the UI processing. The reason your works with alerts is that the alert command halts javascript execution at the point of the alert, then resumes where it left off when the user presses the OK button. This halt gives the browser time to load the requested javascript before the dependent code (below the alert statement) can be executed.
Instead of trying to solve this problem directly, I recommend a different approach: what's the general problem you're trying to solve? EDIT: Somehow an "a" got in front of that synchronously. Big big difference. Apologies! |
| Page 1 of 1 | [ 7 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group