Bug Tracker

Modify

Ticket #407 (closed bug: fixed)

Opened 7 years ago

Last modified 7 years ago

getScript and Safari

Reported by: aercolino at yahoo.c Owned by:
Priority: major Milestone: 1.1a
Component: ajax Version: 1.1a
Keywords: Cc:
Blocking: Blocked by:

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

ajax.js.patch Download (1.6 KB) - added by pmclanahan 7 years ago.
Patch file from my post on 11-20-2006
ajax.js.2.patch Download (1.6 KB) - added by pmclanahan 7 years ago.
Patch file from my post on 11-20-2006
ajax.js.patch.txt Download (1.6 KB) - added by pmclanahan 7 years ago.
Patch file from my post on 11-20-2006

Change History

comment:1 Changed 7 years ago by anonymous

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.

comment:2 Changed 7 years ago by aercolino@…

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

Changed 7 years ago by pmclanahan

Patch file from my post on 11-20-2006

Changed 7 years ago by pmclanahan

Patch file from my post on 11-20-2006

Changed 7 years ago by pmclanahan

Patch file from my post on 11-20-2006

comment:3 Changed 7 years ago by pmclanahan

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 7 years ago by joern

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 7 years ago by joern

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 7 years ago by joern

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 7 years ago by andrea

I think that Jeff sais something about Safari support of eval.call(window, data)

comment:8 Changed 7 years ago by joern

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 7 years ago by joern

  • Summary changed from getScript and IE7 to getScript and Safari

Fixed for IE7, but won't fix for Safari. If anyone finds a more reliable workaround for Safari...

comment:10 Changed 7 years ago by joern

  • Status changed from new to closed
  • Resolution set to fixed

No way to fix it for safari.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.