[jQuery] Re: getscript without parameters... an alernative?
hi Eric, I don't understand what you mean... the functions in script.js (called via getScript) work if I call $.getScript but I wanna call these functions from outside (after script is loaded), so I can pass some parameter to the functions that are inside script.js. $.getScript is not called when the page is loaded (I think that's what you mean). I'm firing it via Firebug console. thanks, Pere Eric Garside wrote: If you call $.getScript after your regular scripts are already loaded, domready will not fire again. On Feb 4, 8:16 am, pere roca pero...@gmail.com wrote: hi all, if I'm not wrong we cannot send parameters to a script called by getScript function; so, if we download or get the script and then we call a function inside the script, shouldn't it work? the function is there, now in our browser... but doesn't work. $.getScript('script.js'); x(); script.js: $(document).ready(function(){ //x function is declared as global x=function(datas) { alert(datas) }; }) Thanks!! -- View this message in context:http://www.nabble.com/getscript-without-parameters...-an-alernative--... Sent from the jQuery General Discussion mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/getscript-without-parameters...-an-alernative--tp21829807s27240p21831561.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: getscript without parameters... an alernative?
Oh, neat. I didn't know jQuery continued to fire docready code after it loaded. Awesome. :D On Feb 4, 10:14 am, Ricardo Tomasi ricardob...@gmail.com wrote: Actually after the document has loaded, any function passed to $ (document).ready() will fire immediately. Also functions are called in the order they were added, so you can put it inside the getScript callback like this: $(document).ready(function(){ x = function(d){ alert(d) }; }); $.getScript('script.js', function(){ $(function(){ x('script loaded and DOM ready'); }); }); getScript() will be fired before DOM ready, then it's callback will add a function to $(doc).ready() which will execute after the function assignment. cheers, - ricardo On Feb 4, 12:53 pm, Eric Garside gars...@gmail.com wrote: Basically, the problem is this here: $(document).ready(function(){ You wrapped it inside an event that will only fire when the document throws its ready event. If you include the script after the page is loaded, regardless from where, th event will never fire. If you remove the $(document).ready(function(){ wrapper from script.js (called via getScript), it will work a lot easier. I've done a small snippet which does javascript backloading, which includes js files after the page has loaded. Worst case, it should still give you some idea of how to use a callback with getScript to fire a defined function within the script.js file. http://snipplr.com/view/10368/jquery-automatic-script-includer/ On Feb 4, 9:32 am, pere roca pero...@gmail.com wrote: hi Eric, I don't understand what you mean... the functions in script.js (called via getScript) work if I call $.getScript but I wanna call these functions from outside (after script is loaded), so I can pass some parameter to the functions that are inside script.js. $.getScript is not called when the page is loaded (I think that's what you mean). I'm firing it via Firebug console. thanks, Pere Eric Garside wrote: If you call $.getScript after your regular scripts are already loaded, domready will not fire again. On Feb 4, 8:16 am, pere roca pero...@gmail.com wrote: hi all, if I'm not wrong we cannot send parameters to a script called by getScript function; so, if we download or get the script and then we call a function inside the script, shouldn't it work? the function is there, now in our browser... but doesn't work. $.getScript('script.js'); x(); script.js: $(document).ready(function(){ //x function is declared as global x=function(datas) { alert(datas) }; }) Thanks!! -- View this message in context:http://www.nabble.com/getscript-without-parameters...-an-alernative--... Sent from the jQuery General Discussion mailing list archive at Nabble.com. -- View this message in context:http://www.nabble.com/getscript-without-parameters...-an-alernative--... Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: getscript without parameters... an alernative?
Actually after the document has loaded, any function passed to $ (document).ready() will fire immediately. Also functions are called in the order they were added, so you can put it inside the getScript callback like this: $(document).ready(function(){ x = function(d){ alert(d) }; }); $.getScript('script.js', function(){ $(function(){ x('script loaded and DOM ready'); }); }); getScript() will be fired before DOM ready, then it's callback will add a function to $(doc).ready() which will execute after the function assignment. cheers, - ricardo On Feb 4, 12:53 pm, Eric Garside gars...@gmail.com wrote: Basically, the problem is this here: $(document).ready(function(){ You wrapped it inside an event that will only fire when the document throws its ready event. If you include the script after the page is loaded, regardless from where, th event will never fire. If you remove the $(document).ready(function(){ wrapper from script.js (called via getScript), it will work a lot easier. I've done a small snippet which does javascript backloading, which includes js files after the page has loaded. Worst case, it should still give you some idea of how to use a callback with getScript to fire a defined function within the script.js file. http://snipplr.com/view/10368/jquery-automatic-script-includer/ On Feb 4, 9:32 am, pere roca pero...@gmail.com wrote: hi Eric, I don't understand what you mean... the functions in script.js (called via getScript) work if I call $.getScript but I wanna call these functions from outside (after script is loaded), so I can pass some parameter to the functions that are inside script.js. $.getScript is not called when the page is loaded (I think that's what you mean). I'm firing it via Firebug console. thanks, Pere Eric Garside wrote: If you call $.getScript after your regular scripts are already loaded, domready will not fire again. On Feb 4, 8:16 am, pere roca pero...@gmail.com wrote: hi all, if I'm not wrong we cannot send parameters to a script called by getScript function; so, if we download or get the script and then we call a function inside the script, shouldn't it work? the function is there, now in our browser... but doesn't work. $.getScript('script.js'); x(); script.js: $(document).ready(function(){ //x function is declared as global x=function(datas) { alert(datas) }; }) Thanks!! -- View this message in context:http://www.nabble.com/getscript-without-parameters...-an-alernative--... Sent from the jQuery General Discussion mailing list archive at Nabble.com. -- View this message in context:http://www.nabble.com/getscript-without-parameters...-an-alernative--... Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: getscript without parameters... an alernative?
Basically, the problem is this here: $(document).ready(function(){ You wrapped it inside an event that will only fire when the document throws its ready event. If you include the script after the page is loaded, regardless from where, th event will never fire. If you remove the $(document).ready(function(){ wrapper from script.js (called via getScript), it will work a lot easier. I've done a small snippet which does javascript backloading, which includes js files after the page has loaded. Worst case, it should still give you some idea of how to use a callback with getScript to fire a defined function within the script.js file. http://snipplr.com/view/10368/jquery-automatic-script-includer/ On Feb 4, 9:32 am, pere roca pero...@gmail.com wrote: hi Eric, I don't understand what you mean... the functions in script.js (called via getScript) work if I call $.getScript but I wanna call these functions from outside (after script is loaded), so I can pass some parameter to the functions that are inside script.js. $.getScript is not called when the page is loaded (I think that's what you mean). I'm firing it via Firebug console. thanks, Pere Eric Garside wrote: If you call $.getScript after your regular scripts are already loaded, domready will not fire again. On Feb 4, 8:16 am, pere roca pero...@gmail.com wrote: hi all, if I'm not wrong we cannot send parameters to a script called by getScript function; so, if we download or get the script and then we call a function inside the script, shouldn't it work? the function is there, now in our browser... but doesn't work. $.getScript('script.js'); x(); script.js: $(document).ready(function(){ //x function is declared as global x=function(datas) { alert(datas) }; }) Thanks!! -- View this message in context:http://www.nabble.com/getscript-without-parameters...-an-alernative--... Sent from the jQuery General Discussion mailing list archive at Nabble.com. -- View this message in context:http://www.nabble.com/getscript-without-parameters...-an-alernative--... Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: getscript without parameters... an alernative?
If you call $.getScript after your regular scripts are already loaded, domready will not fire again. On Feb 4, 8:16 am, pere roca pero...@gmail.com wrote: hi all, if I'm not wrong we cannot send parameters to a script called by getScript function; so, if we download or get the script and then we call a function inside the script, shouldn't it work? the function is there, now in our browser... but doesn't work. $.getScript('script.js'); x(); script.js: $(document).ready(function(){ //x function is declared as global x=function(datas) { alert(datas) }; }) Thanks!! -- View this message in context:http://www.nabble.com/getscript-without-parameters...-an-alernative--... Sent from the jQuery General Discussion mailing list archive at Nabble.com.