Opened 16 years ago
Closed 16 years ago
#407 closed bug (fixed)
getScript and Safari
Reported by: | aercolino at yahoo.c | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.1a |
Component: | ajax | Version: | 1.1a |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
While developing the PunchCard widget I've found a problem with getScript in IE7.
If you are interested in helping me, I've isolated the issue here: http://www.mondotondo.com/aercolino/punchcard/test-getScript-error/
Attachments (3)
Change History (13)
comment:1 Changed 16 years ago by
comment:2 Changed 16 years ago by
Please refer to the page http://www.mondotondo.com/aercolino/punchcard/test-getScript-error/ for testing the general solution based on a script by Jeff Watkins. I provide a link to Jeff's post documenting its findings.
I think that Jeff's installScript function for evaluating a script in the global scope should be added to the core of jQuery, with the signature "void jQuery.eval( String script )" and every call in jQuery to window.eval should be replaced by a call to jQuery.eval
execScript seems to be available since IE4.x at least (maybe before too)
execScript gets a second optional argument for the language: it defaults to jscript
comment:3 Changed 16 years ago by
Update: I checked the test suite in Safari 1.3.2 and some stuff is broken: "9 tests of 283 failed." The only error in ajax.js however was serialize, and all of the failures existed prior to applying my patch. In other words, it fails in Safari in exactly the same way.
Another note: this last patch I posted from today (11/20/2006) is not in addition to the one posted previously, it is meant to be instead of.
Paul
comment:4 Changed 16 years ago by
Thanks Paul. I just commited your patch and modified one test, it runs fine on FF1.5, IE6, IE7 and Opera 9. Though I'm not sure if the eval/global context stuff is really covered.
Unfortuatenetely I can't declare this bug is fixed... stupid spam :/
comment:5 Changed 16 years ago by
This stuff should be extracted as $.eval:
if(window.execScript) window.execScript(data); else setTimeout(data, 0)
And then replace that call within httpData and evalScripts.
API change scheduled for 1.1.
comment:6 Changed 16 years ago by
Using setTimeout causes the eval to run asynchrounosly, which is ugly. Using eval.call( window, data) works fine together with window.execScript. According to my tests it runs for FF1.5, IE6, IE7 and Opera 9.
comment:7 Changed 16 years ago by
I think that Jeff sais something about Safari support of eval.call(window, data)
comment:8 Changed 16 years ago by
Latest version for $.eval (or rather, $.globalEval)
jQuery.globalEval = function(data){ if(window.execScript) // msie window.execScript(data); else if(jQuery.browser.safari) // safari window.setTimeout(data,0); else // all others eval.call( window, data ); }
eval.call or self.eval won't work either on Safari. Looks like we must live with the timeout, but that must be documented.
comment:9 Changed 16 years ago by
Summary: | getScript and IE7 → getScript and Safari |
---|
Fixed for IE7, but won't fix for Safari. If anyone finds a more reliable workaround for Safari...
comment:10 Changed 16 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
No way to fix it for safari.
You must not use either of the following two methods (they're synonymous) when using getScript when defining functions in the scripts to be loaded.
function myFunc(){}
var myFunc = function(){}
However, if you define functions like this:
myFunc = function(){} note the lack of "var"
Then it will be available and work fine. I've found no fix for this in jQuery source. For now we just have to be careful of the scripts we load in.
You can also keep using the first method above and just define the variable in the global scope earlier in the script file like so:
myFunc = myOtherFunc = {}; function myFunc(){} etc...
This was tested against SVN jQuery and IE7.