Why not use document.createElement("script") !?

Here is my solution and work well in IE6 and FF2

// replace the call for eval.call(window, script)
jQuery.evalJS = function (script) {
   var js = document.createElement('SCRIPT');
       js.type = 'text/javascript';
       js.text = script;
       document.body.appendChild(js);
};

// @override
jQuery.getScript = function (src, callback) {
   var js = document.createElement('SCRIPT');
       js.type = 'text/javascript';
       js.src = src;
       js.defer = true;
       document.body.appendChild(js);
}



On 11/23/06, Karl Rudd <[EMAIL PROTECTED]> wrote:

I can confirm that (window.execScript || self.eval)(script) does NOT
work in Safari 2.0.4 (419.3). It also does not work in Opera 9.

The test harness I used was:

       var local = "test";
       (function() {
               var s = 'function blah(){alert("from blah()");};
local="changed";';
               (window.execScript || self.eval)( s );  // IE, Mozilla
               //eval.call( window, s ); // Opera, Mozilla
               // window.setTimeout(s,0); // blah() fails in all
       })();
       alert(local);
       blah();

Karl Rudd

On 11/23/06, Paul McLanahan <[EMAIL PROTECTED]> wrote:
> That's a cool fix. I really like your syntax.  However, Safari still
> won't eval that globally either using self.eval or window.eval.  That
> is as tested on Safari 1.3, I don't have easy access to 2.0.  I can
> try it there later though.
>
> On 11/22/06, Francisco Brito <[EMAIL PROTECTED]> wrote:
> > I don't have access to safari right now, but perhaps this might work:
> >
> > self.eval(); // or window.self.eval if you can see the performance
change
> >
> > I remember having a similar problem with firefox a bit ago using
> > window.eval() and that fixed it. I ended up with:
> >
> > (window.execScript || self.eval)(script);
> >
> > I have a fresh post about this:
> >
http://nullisnull.blogspot.com/2006/11/executing-scripts-with-xmlhttprequest.html
> > I'm curious to see if it works with Safari.
> >
> > --
> > Brito
> >
> >
> >
> > On 11/22/06, Paul McLanahan <[EMAIL PROTECTED]> wrote:
> > > I just checked eval.call(window,data) on Safari 2.0.4 and it did NOT
> > > work.  The function was available immediately, but only in the scope
> > > of the httpData function. And with window.setTimeout it was
available
> > > globally, but not immediately inside of httpData....
> > >
> > > <grumbles:incoherrently/>
> > >
> > > Example...
> > >
> > > external file
> > > ========================
> > > function gsTest(){alert("Success!!");}
> > > ========================
> > >
> > > inside of $.httpData()
> > > ========================
> > > window.execScript?window.execScript(data):eval.call( window, data );
> > > gsTest();
> > > ========================
> > >
> > > In Safari 1.3 or 2.0 the above will alert "Success!!", however,
> > > clicking on <a href="#" onclick="gsTest()">test</a> in the document
> > > does not work.
> > >
> > > inside of $.httpData()
> > > ========================
> > >
> > window.execScript?window.execScript(data):jQuery.browser.safari
?window.setTimeout(data,0):eval.call(
> > > window, data );
> > > gsTest();
> > > ========================
> > >
> > > In Safari 1.3 or 2.0 the above will NOT alert "Success!!"
immediately.
> > > It will throw an error. But, clicking on a link like <a href="#"
> > > onclick="gsTest()">test</a> in the document will work.
> > >
> > > Anyone got any ideas? I'm fresh out. If we can't solve this, then I
> > > suggest we keep the window.setTimeout in there for Safari since I
> > > believe that global availability will be the feature most often used
> > > and the 10ms problem will be encountered very rarely.  I completely
> > > agree with Jörn that it should be documented in the code of the
> > > function.
> > >
> > > On 11/22/06, Jörn Zaefferer <[EMAIL PROTECTED]> wrote:
> > > > Paul McLanahan schrieb:
> > > > > jQuery.gEval = 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 );
> > > > > }
> > > > >
> > > > > What do you guys think? Works in all my tests so far, but again,
I
> > > > > don't have SVN access here so.... I'm SOL as far as the sweet
new test
> > > > > suite goes.
> > > > >
> > > > Looks good for me. We should note somewhere that the evaluation is
> > > > asynchronous for Safari. If anyone actually happens to stumble
about
> > > > that problem, it's nice to have it documented.
> > > >
> > > > Could you please check Safari 2.x? It would be nice to use
eval.call()
> > > > if possible...
> > > >
> > > > --
> > > > Jörn Zaefferer
> > > >
> > > > http://bassistance.de
> > > >
> > > >
> > > > _______________________________________________
> > > > jQuery mailing list
> > > > [email protected]
> > > > http://jquery.com/discuss/
> > > >
> > >
> > > _______________________________________________
> > > jQuery mailing list
> > > [email protected]
> > > http://jquery.com/discuss/
> > >
> >
> >
> >
> > --
> > Francisco Brito
> >
> > software:            http://nullisnull.blogspot.com
> > photography:
> > http://www.flickr.com/photos/darkgoyle
> > everything else:   http://brito.mindsay.com
> > _______________________________________________
> > jQuery mailing list
> > [email protected]
> > http://jquery.com/discuss/
> >
> >
> >
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/




--
Best regards,
沈志川 (Benx)
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to