Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > > > Maybe it has to do with your security-setings in IE. You need to allow > > > scripts > > > to access "secure" ActiveX-Controls, as you need for all ajax stuff. > > > Otherwise there will of course not be any chance to get an > > > XMLHttpRequest object. > > > > But that cannot be the case because I tested your page and it worked... > > so my IE security-settings must be OK for jsPAX. Have you been able to track down that problem now? I'd be very fond to know the solution. > Yes. I have not had coloured text in Konqueror (Linux), IE 5.0 (Linux/Wine) > and Opera 7.54 (WindowsXP) that is all. All others I have checked with now > have the colours (FF 2, Opera 9, IE 5.5, IE 6 , IE 7 all with Linux and > Wine and FF 2 and IE 7 with Windows XP). Of course I only use Wine for IE - I just noticed, that my phrasing was misleading here. FF and Opera run natively on my Linux system. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > > Maybe it has to do with your security-setings in IE. You need to allow > > scripts > > to access "secure" ActiveX-Controls, as you need for all ajax stuff. > > Otherwise there will of course not be any chance to get an XMLHttpRequest > > object. > > But that cannot be the case because I tested your page and it worked... > so my IE security-settings must be OK for jsPAX. Maybe IE sorts your local files in another security domain. You can of course have completely different settings for different machines. > Could you please confirm that the page you see in FF and IE both show > colored code? Yes. I have not had coloured text in Konqueror (Linux), IE 5.0 (Linux/Wine) and Opera 7.54 (WindowsXP) that is all. All others I have checked with now have the colours (FF 2, Opera 9, IE 5.5, IE 6 , IE 7 all with Linux and Wine and FF 2 and IE 7 with Windows XP). > You'll begin to think I'm pedant, but in FF I see colored > code, no matter if I reload. I think, that IE is awkward ;-) I have strange behaviour of IE 7 with other web applications as well so don't bother. > On the contrary, in IE7 I can see at first > black code, and after a reload the page disappears and the progress bar > keeps loading, and loading, and loading... (it never stops) Hm, I see the colours before and after reloading both with Windows XP and with Wine. Reloading is no problem with IE 7 here as well. It just works as expected. It looks as if problems with the coloring code and reloading problems relate to each other somehow. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > I'm getting something similar in IE7 as well (FF and Opera seem fine). A > "View Source" reveals this: > > Hm, that is nothing that could have been created with jsPax. I don't use deferred scripts and there is no "__ie_init" anywhere in jsPax as well. I'm not shure what happens there. It looks a bit like what $(document).ready() should do for IE. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
On 1/17/07, Andrea Ercolino <[EMAIL PROTECTED]> wrote: Could you please confirm that the page you see in FF and IE both show colored code? You'll begin to think I'm pedant, but in FF I see colored code, no matter if I reload. On the contrary, in IE7 I can see at first black code, and after a reload the page disappears and the progress bar keeps loading, and loading, and loading... (it never stops) I'm getting something similar in IE7 as well (FF and Opera seem fine). A "View Source" reveals this: and that's it. -- Aaron Heimlich Web Developer [EMAIL PROTECTED] http://aheimlich.freepgs.com ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof Donat wrote: > > Maybe it has to do with your security-setings in IE. You need to allow > scripts > to access "secure" ActiveX-Controls, as you need for all ajax stuff. > Otherwise there will of course not be any chance to get an XMLHttpRequest > object. > But that cannot be the case because I tested your page and it worked... so my IE security-settings must be OK for jsPAX. Could you please confirm that the page you see in FF and IE both show colored code? You'll begin to think I'm pedant, but in FF I see colored code, no matter if I reload. On the contrary, in IE7 I can see at first black code, and after a reload the page disappears and the progress bar keeps loading, and loading, and loading... (it never stops) I've put a test page here: http://www.mondotondo.com/test/chili/test-jspax.html -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8417084 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > > I have no problems with a relative package path > > This is very strange... Did you use the exact files/directories in the zip > I submitted? Yes, I just changed packageBase to the path at my computer. Everything else is exactly the files in the zip. Maybe it has to do with your security-setings in IE. You need to allow scripts to access "secure" ActiveX-Controls, as you need for all ajax stuff. Otherwise there will of course not be any chance to get an XMLHttpRequest object. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof Donat wrote: > > I have no problems with a relative package path > This is very strange... Did you use the exact files/directories in the zip I submitted? -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8392903 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > > But I still have the same problem... > > Here is a zip file. After unzipping, there will be a new "chili" folder > > with a test page and a subfolder. It works in FF1.5.0.9 but does not in > > IE7. http://www.nabble.com/file/5620/chili.zip chili.zip > > Currrently I don't have IE7 at hand - on monday again. Sorry, yesterday there was too muc todo for the customers. Here we go: On Sunday I have installed IEs4Linux on m Linux machine with IE5, IE5.5, IE6 and IE7 all of them except for IE5 worked correctly. Now I have tested on a Windows XP machine with IE7. I have no problems with a relative package path ('packages/'), but an absolute package path to a network device ('//server/share/test/chili/packages/') doesn't work. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > Your test page works now :-) Great :-) > But I still have the same problem... > Here is a zip file. After unzipping, there will be a new "chili" folder > with a test page and a subfolder. It works in FF1.5.0.9 but does not in > IE7. http://www.nabble.com/file/5620/chili.zip chili.zip Currrently I don't have IE7 at hand - on monday again. I tried your code with Firefox 2.0, Opera 9.02 and Konqueror 3.5.5 on Linux. Firefox is OK, Opera has huge linespaces, but shows the colors. Konqueror doesn't do any coloring at all, but an alert() in the calback of $using() in chili.js fires. I guess you have tried that alert with IE as well. BTW.: I usually don't write the packageBase in package_src.js. I keep that as it is an overwrite it outside. That way I don't have any problems when changing to the compressed package.js. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof Donat wrote: > > @Andrea: can you please check, if that was the problem for you? > Your test page works now :-) But I still have the same problem... Here is a zip file. After unzipping, there will be a new "chili" folder with a test page and a subfolder. It works in FF1.5.0.9 but does not in IE7. http://www.nabble.com/file/5620/chili.zip chili.zip -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8313016 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
On 1/12/07, Christof Donat <[EMAIL PROTECTED]> wrote: Erm, yes. I just found that one. It was just trying to fetch the packages from http://jspax.cdonat.de/test/. I have changed that to /test/ now. On the Server jspax.cdonat.de, jspax.org, jspax.de and jspax.com are the same directory. I know this is completely off topic (and I apologize for it), but, IIRC, it's really bad for SEO (Search Engine Optimization) to have identical content at multiple URLs because then they begin competing with each other for rankings. Unless each domain has a separate purpose, (like mirrors or something), I'd chose one domain ( jspax.org would be my pick) and simply have the rest of them redirect to that one. More info: http://www.google.com/support/webmasters/bin/answer.py?answer=35769#quality(look particularly at the fifth bullet point under "Quality guidelines - specific guidelines") and http://www.google.com/support/webmasters/bin/topic.py?topic=8473 (look at the "Setting the preferred domain" section towards the bottom of the page) -- Aaron Heimlich Web Developer [EMAIL PROTECTED] http://aheimlich.freepgs.com ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > >>> http://www.jspax.org/test/ > >> > >> FF, OK. > >> IE, KO: > > > > Hm, It workes for me. I'll see if I can find something strange around the > > point, the error message suggests. > > > > Christof > > For me on IE 6 it pops up a message saying "This page is accessing > information that is not under its control. This poses a security risk. > Do you want to continue?". If I say no it breaks but if I say yes it's > OK... Maybe some security setting in IE can cause it to break? Erm, yes. I just found that one. It was just trying to fetch the packages from http://jspax.cdonat.de/test/. I have changed that to /test/ now. On the Server jspax.cdonat.de, jspax.org, jspax.de and jspax.com are the same directory. @Andrea: can you please check, if that was the problem for you? Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof Donat wrote: > Hi, > >>> http://www.jspax.org/test/ >> FF, OK. >> IE, KO: > > Hm, It workes for me. I'll see if I can find something strange around the > point, the error message suggests. > > Christof For me on IE 6 it pops up a message saying "This page is accessing information that is not under its control. This poses a security risk. Do you want to continue?". If I say no it breaks but if I say yes it's OK... Maybe some security setting in IE can cause it to break? Kelvin :) ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > > http://www.jspax.org/test/ > > FF, OK. > IE, KO: Hm, It workes for me. I'll see if I can find something strange around the point, the error message suggests. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof Donat wrote: > >> Which testsuite? What URL? > > Look at > http://www.jspax.org/test/ > FF, OK. IE, KO: http://www.nabble.com/file/5605/jspax.png -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8296718 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > Which testsuite? What URL? Look at http://www.jspax.org/test/ Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof Donat wrote: > > Hm, that is strange. can you please check, if the testsuite at jquery.org > works correctly with IE for you? It uses exactly the compressed package.js > that is also available for download. > Which testsuite? What URL? -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8296217 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > > Just a guess: Have you tried to use an absolute URL, or at leas an > > absolute > > path here? Maybe Firefox interprets that relative to the current HTML > > page and IE interprets it relative to the js. Then IE tries to > > load "packages/packages/jquery.js" where Firefox loads > > "packages/jquery.js". > > I've tried again with an absolute path "/test/1.5/examples/4/packages/" and > an absolute url "http://localhost/test/1.5/examples/4/packages/";, but still > nothing changes: FF OK, IE KO. Hm, that is strange. can you please check, if the testsuite at jquery.org works correctly with IE for you? It uses exactly the compressed package.js that is also available for download. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof Donat wrote: > > Just a guess: Have you tried to use an absolute URL, or at leas an > absolute > path here? Maybe Firefox interprets that relative to the current HTML page > and IE interprets it relative to the js. Then IE tries to > load "packages/packages/jquery.js" where Firefox loads > "packages/jquery.js". > I've tried again with an absolute path "/test/1.5/examples/4/packages/" and an absolute url "http://localhost/test/1.5/examples/4/packages/";, but still nothing changes: FF OK, IE KO. -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8295561 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > 2.I've wrapped the content of the standard chili.js file inside this: > $using( 'jquery', function() { > ... > $package( 'chili', {} ); > } ); Since you don't load chili.js via jsPax you don't necessarily need the $package()-call, but it doesn't hurt. > 3.I've changed the default path inside package.js to: > $package.packageBase = 'packages/'; Just a guess: Have you tried to use an absolute URL, or at leas an absolute path here? Maybe Firefox interprets that relative to the current HTML page and IE interprets it relative to the js. Then IE tries to load "packages/packages/jquery.js" where Firefox loads "packages/jquery.js". > 6.It works in FF, but it does not in IE. I can not see anything you have done wrong. If my guess proves to be correct I will change the documentation accordingly and think abuout what I can do about it. In all Tests I did, I have used absolute paths ("/test/packages/") or even absolute URLs ("http://www.example.com/test/packages/";), or I have the script that calls $using() in the same directory as the HTML or even embedded into the HTML (like the testsuite). Therefore I did not come accross that problem. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
1. I've put this line at the bottom of the standard jquery.js file not compressed: $package('jquery',{}); 2. I've wrapped the content of the standard chili.js file inside this: $using( 'jquery', function() { ... } ); 3. I've changed the default path inside package.js to: $package.packageBase = 'packages/'; 4. I've added this markup to mypage.html: 5. I've put the modified chili.js and jquery.js files inside the 'packages' folder, so the folder from where the page is loaded contains: mypage.html, package.js, packages/ 6. It works in FF, but it does not in IE. -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8289335 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > >> Yes, I downloaded it short before. > >> Please, tell me when I can download the fixed version, and I'll test > >> again > > > > I just have uploaded the current version again. Please try again. > > I've just downloaded and tried again but... nothing changed :( Have you tried the testsuite that I have online? It worked for me with IE7. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof Donat wrote: > >> Yes, I downloaded it short before. >> Please, tell me when I can download the fixed version, and I'll test >> again > I just have uploaded the current version again. Please try again. > I've just downloaded and tried again but... nothing changed :( -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8243235 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > Yes, I downloaded it short before. > Please, tell me when I can download the fixed version, and I'll test again I just have uploaded the current version again. Please try again. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof Donat wrote: > >> > Well, I don't know about any guarantees, but it works in all test I did >> > (with >> > the loaded script delayed, etc.) >> >> I'm trying to apply your jsPAX to my Chili setup, but it works in FF1.5 >> and >> not in IE7, which does not return any error and does not show the page, >> just keeps loading indefinitely. > > Have you just downloaded that version? The problem is, that IE7 has a > XMLHttpRequest Object that does not need ActiveX, but doesn't work like > the > one of Firefox, Safari, Konqueror and Opera. In the current version I used > the ActiveX-XMLHttpRequest every time ActiveX is available - which at > least > works as expected. > > If you just have downloaded it, I put the wrong version online. > Yes, I downloaded it short before. Please, tell me when I can download the fixed version, and I'll test again :-) -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8189949 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > > Well, I don't know about any guarantees, but it works in all test I did > > (with > > the loaded script delayed, etc.) > > I'm trying to apply your jsPAX to my Chili setup, but it works in FF1.5 and > not in IE7, which does not return any error and does not show the page, > just keeps loading indefinitely. Have you just downloaded that version? The problem is, that IE7 has a XMLHttpRequest Object that does not need ActiveX, but doesn't work like the one of Firefox, Safari, Konqueror and Opera. In the current version I used the ActiveX-XMLHttpRequest every time ActiveX is available - which at least works as expected. If you just have downloaded it, I put the wrong version online. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof Donat wrote: > > Well, I don't know about any guarantees, but it works in all test I did > (with > the loaded script delayed, etc.) > Hi Christof. I'm trying to apply your jsPAX to my Chili setup, but it works in FF1.5 and not in IE7, which does not return any error and does not show the page, just keeps loading indefinitely. Andrea -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8177701 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > > As you might know scripts are evaluated in the > > order they are in the HTML code, that is that script will be > > evaluated before script2 is. > > Interesting - is that guaranteed even when the scripts are added > dynamically? Well, I don't know about any guarantees, but it works in all test I did (with the loaded script delayed, etc.) Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
> > That looks really dodgy, sorry. > > > > What if the browser downloads script and script2 at the > > same time, and script2 finishes first? > > It doesn't. script2 is not downloaded at all, it is like a > inline script. Ah, I wasn't paying close enough attention to the code. :-) > As you might know scripts are evaluated in the > order they are in the HTML code, that is that script will be > evaluated before script2 is. Interesting - is that guaranteed even when the scripts are added dynamically? -Mike ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > That looks really dodgy, sorry. > > What if the browser downloads script and script2 at the same time, and > script2 finishes first? It doesn't. script2 is not downloaded at all, it is like a inline script. As you might know scripts are evaluated in the order they are in the HTML code, that is that script will be evaluated before script2 is. It does work in all browsers I have tested jsPax with. The only problem I know of is that script2 will also be evaluated if script can not be loaded sucessfully. Then as soon as the browser knows that it can not load script, it evaluates script2. > Instead, simply edit your copy of jquery.js and add one like of code at the > end of the file, to call a "ready" function that you've defined in your > already-running code. If you have jQuery plugins that your code depends on, > merge them all into jquery.js and add that function call at the very end. I have a simple line at the end of jquery.js: $package('jquery',{}); The plugins are wraped with $using('jquery', function() { ... $package('jquery.myplugin',{}); }); If I then decide, I need the foo- and the bar-plugin in my code I simply do $using(['jquery.foo','jquery.bar'], function() { alert('jquery and foo plugin are loaded now'); }); That way I load much of the needed functions on demand. Which reduces startup time - paied with eventual delays at the first use of some functions. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Michael Geary schrieb: > Hmm... This would make a nice patch for jQuery itself - when it concatenates > all the files to make the various "dist" versions, add this line to the end > of the merged code: > > window.jQuery_onload && jQuery_onload(); > > John et al, what do you think? > The implementation is easy enough, just add that to src/outro.js, that is always at the end of the distribution. -- Jörn Zaefferer http://bassistance.de ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
> > I'm afraid that I simply don't take Safari users into > > account. Hardly a great thing, but I focus on three > > browsers: Firefox and IE7, and then IE6. > > In that order. The work I do is targetted at corporate > > users who run Windows 2000 and Firefox, and all the > > JS work I do is for those users. > Then your solution is almost OK for you. Here is a usable > version ;-) > > (function() { > var addScriptCounter = 0; > > function addScript( url, callback ) { > var script = document.createElement( 'script' ); > script.myLoadHandler = callback; > script.id = 'dynamicallyLoadedScript_'+addScriptCounter; > script.type = 'text/javascript'; > script.charset = 'utf-8'; > script.src = url; > > var script2 = document.createElement( 'script' ); > script2.type = 'text/javascript'; > script2.charset = 'utf-8'; > script2.appendChild( > document.createTextNode( > '(function(){'+ > 'document.getElementById(\'dynamicallyLoadedScript_'+ > addScriptCounter+'\').myLoadHandler();})()'; > )); > > var head = document.getElementsByTagName('head')[0]; > head.appendChild( script ); > head.appendChild( script2 ); > > addScriptCounter++; > } > })() > > Usage: > > addScript('jquery.js', function() { > alert('horay, jQuery is available'); > }); > alert('jQuery is not necessarily available here'); > > The second script tag will be evaluated after the first one > has been loaded and evaluated. At least that works for all > browsers I have tested with, except those Safari versions > and very old browsers without a usable DOM implementation. That looks really dodgy, sorry. What if the browser downloads script and script2 at the same time, and script2 finishes first? Instead, simply edit your copy of jquery.js and add one like of code at the end of the file, to call a "ready" function that you've defined in your already-running code. If you have jQuery plugins that your code depends on, merge them all into jquery.js and add that function call at the very end. Hmm... This would make a nice patch for jQuery itself - when it concatenates all the files to make the various "dist" versions, add this line to the end of the merged code: window.jQuery_onload && jQuery_onload(); John et al, what do you think? -Mike -Mike ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
That's a good, workable solution! Cheers, Dan Christof Donat wrote: > > Hi, > >> I'm afraid that I simply don't take Safari users into account. Hardly a >> great thing, but I focus on three browsers: Firefox and IE7, and then >> IE6. >> In that order. The work I do is targetted at corporate users who run >> Windows 2000 and Firefox, and all the JS work I do is for those users. > > Then your solution is almost OK for you. Here is a usable version ;-) > > (function() { > var addScriptCounter = 0; > > function addScript( url, callback ) { > var script = document.createElement( 'script' ); > script.myLoadHandler = callback; > script.id = 'dynamicallyLoadedScript_'+addScriptCounter; > script.type = 'text/javascript'; > script.charset = 'utf-8'; > script.src = url; > > var script2 = document.createElement( 'script' ); > script2.type = 'text/javascript'; > script2.charset = 'utf-8'; > script2.appendChild( > document.createTextNode( > '(function(){'+ > 'document.getElementById(\'dynamicallyLoadedScript_'+ > addScriptCounter+'\').myLoadHandler();})()'; > )); > > var head = document.getElementsByTagName('head')[0]; > head.appendChild( script ); > head.appendChild( script2 ); > > addScriptCounter++; > } > })() > > Usage: > > addScript('jquery.js', function() { > alert('horay, jQuery is available'); > }); > alert('jQuery is not necessarily available here'); > > The second script tag will be evaluated after the first one has been > loaded > and evaluated. At least that works for all browsers I have tested with, > except those Safari versions and very old browsers without a usable DOM > implementation. > > If jQuery cannot be loaded successfully (wrong url e.g.), your callback > will > still be called, and will fail as soon as it tries to access jQuery. > > If you use a XMLHttpRequest, you can distinguish the case when loading was > not > successfull from successfull loading before you really call the callback. > By > the way you also get it working for Safari, but keep out those browsers > without a XMLHttpRequest implementation. For them jsPax falls back to > adding > script tags via DOM. > > That does not work only for the very old browsers without a usable DOM > implementation. There is also a fallback for them in jsPax, but I have not > really tested it, because I don't have such a browser at hand - > theoretically > it should work. > > Christof > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8167439 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, > I'm afraid that I simply don't take Safari users into account. Hardly a > great thing, but I focus on three browsers: Firefox and IE7, and then IE6. > In that order. The work I do is targetted at corporate users who run > Windows 2000 and Firefox, and all the JS work I do is for those users. Then your solution is almost OK for you. Here is a usable version ;-) (function() { var addScriptCounter = 0; function addScript( url, callback ) { var script = document.createElement( 'script' ); script.myLoadHandler = callback; script.id = 'dynamicallyLoadedScript_'+addScriptCounter; script.type = 'text/javascript'; script.charset = 'utf-8'; script.src = url; var script2 = document.createElement( 'script' ); script2.type = 'text/javascript'; script2.charset = 'utf-8'; script2.appendChild( document.createTextNode( '(function(){'+ 'document.getElementById(\'dynamicallyLoadedScript_'+ addScriptCounter+'\').myLoadHandler();})()'; )); var head = document.getElementsByTagName('head')[0]; head.appendChild( script ); head.appendChild( script2 ); addScriptCounter++; } })() Usage: addScript('jquery.js', function() { alert('horay, jQuery is available'); }); alert('jQuery is not necessarily available here'); The second script tag will be evaluated after the first one has been loaded and evaluated. At least that works for all browsers I have tested with, except those Safari versions and very old browsers without a usable DOM implementation. If jQuery cannot be loaded successfully (wrong url e.g.), your callback will still be called, and will fail as soon as it tries to access jQuery. If you use a XMLHttpRequest, you can distinguish the case when loading was not successfull from successfull loading before you really call the callback. By the way you also get it working for Safari, but keep out those browsers without a XMLHttpRequest implementation. For them jsPax falls back to adding script tags via DOM. That does not work only for the very old browsers without a usable DOM implementation. There is also a fallback for them in jsPax, but I have not really tested it, because I don't have such a browser at hand - theoretically it should work. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Christof, I'm afraid that I simply don't take Safari users into account. Hardly a great thing, but I focus on three browsers: Firefox and IE7, and then IE6. In that order. The work I do is targetted at corporate users who run Windows 2000 and Firefox, and all the JS work I do is for those users. About three people in our company have a Mac, and all of them use FF, so Safari simply doesn't come into my considerations when coding. Thanks though. It's always good to know a browsers limitations. :-) Cheers, Dan Christof Donat wrote: > > Hi, > >>function addScript( url ) { >> var script = document.createElement( 'script' ); >> script.type = 'text/javascript'; >> script.charset = 'utf-8'; >> script.src = url; >> document.getElementsByTagName('head')[0].appendChild( script ); >>}; > > There are safari-versions which don't eval scripts like that. That is the > reason, why jspax uses XMLHttpRequest and eval() if possible and inserts a > script tag if XMLHttpRequest is not available (that deffinatelly is not > that > Safari version then). > >> addScript('jquery.js'); > > And then you guess the time when jquery is loaded. You can not expect that > jQuery is available when addScript returns. With jsPax you use > > $using('jquery',function() { > alert('jQuery is now available'); > }); > >> I would recommend doing a search on the Nabble mailing list page for >> this, >> as it has been covered many times before. > > Yes, and we had the problem with Safari in almost every thread about this > issue. We also had the problem of knowing the moment, the script has been > loaded almost in every one of those threads. > > Sorry Dan, but I thought you really should have come across those issues. > > Christof > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8156061 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
Hi, >function addScript( url ) { > var script = document.createElement( 'script' ); > script.type = 'text/javascript'; > script.charset = 'utf-8'; > script.src = url; > document.getElementsByTagName('head')[0].appendChild( script ); >}; There are safari-versions which don't eval scripts like that. That is the reason, why jspax uses XMLHttpRequest and eval() if possible and inserts a script tag if XMLHttpRequest is not available (that deffinatelly is not that Safari version then). > addScript('jquery.js'); And then you guess the time when jquery is loaded. You can not expect that jQuery is available when addScript returns. With jsPax you use $using('jquery',function() { alert('jQuery is now available'); }); > I would recommend doing a search on the Nabble mailing list page for this, > as it has been covered many times before. Yes, and we had the problem with Safari in almost every thread about this issue. We also had the problem of knowing the moment, the script has been loaded almost in every one of those threads. Sorry Dan, but I thought you really should have come across those issues. Christof ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] dynamic loading of jquery.js into my web page
function addScript( url ) { var script = document.createElement( 'script' ); script.type = 'text/javascript'; script.charset = 'utf-8'; script.src = url; document.getElementsByTagName('head')[0].appendChild( script ); }; You would use it by doing something like: addScript('jquery.js'); I would recommend doing a search on the Nabble mailing list page for this, as it has been covered many times before. Cheers, Dan Atkinson bohumil wrote: > > Hello. > > I want to load file jquery.js into my web page dynamically. I tried this > code: > > script = document.createElement('script'); > script.src = 'jquery.js'; > x = document.getElementsByTagName('head')[0]; > x.appendChild(script); > > this code works with my other javascript file, but it doesn't work > jquery.js. Could you help me please? > > -- View this message in context: http://www.nabble.com/dynamic-loading-of-jquery.js-into-my-web-page-tf2905089.html#a8122926 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/