[jQuery] Re: Loading dynamic JS libraries with jQuery

2008-01-16 Thread fuzziman


Not sure if this is what you mean, but I can load external JS using a
bookmarklet.
For example, loading jquery onto any arbitary web page:

javascript:var
s=document.createElement('script');s.type='text/javascript';s.src='http://jqueryjs.googlecode.com/files/jquery-1.1.4.js';document.body.appendChild(s);void(s);
load jquery 


Jeroen Geusebroek wrote:
 
 
 AFAIK browsers do not support loading external JS after the DOM has
 loaded.
 
 

-- 
View this message in context: 
http://www.nabble.com/Loading-dynamic-JS-libraries-with-jQuery-tp14856398s27240p14864494.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.



[jQuery] Re: Loading dynamic JS libraries with jQuery

2008-01-16 Thread Hamish Campbell

What is the output when you fire this:

function loadJavascript(scriptFile) {
var scriptsPath;

// Builds the correct scripts path
scriptsPath = $('script').attr('src');
scriptsPath = scriptsPath.replace(/\w+\.js$/, '');

$.getScript(scriptsPath + scriptFile + .js, function(data,
textStatus){
alert('status of request was: ' + textStatus);
});
}



On Jan 16, 3:17 pm, Nazgulled [EMAIL PROTECTED] wrote:
 Any hints why $.getScript() is not working as it should?

 On Jan 15, 11:28 pm, Jeroen [EMAIL PROTECTED] wrote:



  On Jan 16, 2008 12:20 AM, Nazgulled [EMAIL PROTECTED] wrote:

   Hi,
   I'm trying to load JS files (libraries) dynamically at run-time with
   jQuery but I'm not being able to...

  AFAIK browsers do not support loading external JS after the DOM has loaded.
  I think this is the reason for the $.getScript(script.js, function(){ do
  stuff...   }); function.

  I use this in my projects and it works great and is a much cleaner
  alternative. You could
  even bind it to an event so it only get's loaded after the event is
  triggered (very cool).

  --
  Jeroen- Hide quoted text -

 - Show quoted text -


[jQuery] Re: Loading dynamic JS libraries with jQuery

2008-01-15 Thread Scott Trudeau
Look at $.getScript:

http://docs.jquery.com/Ajax/jQuery.getScript

Try something like:

$(document).ready(function() {
  $.getScript('script/jquery.form.js');
});

You can wrap $.getScript in your function to do the script path prepend and
.js append. No need to do all the messy DOM stuff yourself. That's what
jQuery is for. ;)

Scott

On Jan 15, 2008 6:20 PM, Nazgulled [EMAIL PROTECTED] wrote:


 Hi,
 I'm trying to load JS files (libraries) dynamically at run-time with
 jQuery but I'm not being able to... I thought I had this working
 before but now it's not. Here's my code:

 INDEX.HTML
 html
 head
 script type=text/javascript src=scripts/jquery.js/script
 script type=text/javascript src=scripts/global.js/script
 /head
 body
 /body
 /html

 GLOBAL.JS
 function loadJavascript(scriptFile) {
var scriptsPath;

// Builds the correct scripts path
scriptsPath = $('script').attr('src');
scriptsPath = scriptsPath.replace(/\w+\.js$/, '');

// Creates the script element and appends it to the head
$(document.createElement('script'))
.attr('src',  scriptsPath + scriptFile + .js)
.attr('type', 'text/javascript')
.appendTo('head');
 }

 $(document).ready(function() {
// Dynamically loads a list of javascript files
loadJavascript('jquery.form');
 }

 It should have created a script element like this:
 script type=text/javascript src=scripts/jquery.form.js/script
 And appended it to the head element, but it didn't work...

 I'm using the latest jQuery v1.2.2. Hope someone can clarify this to
 me... Why can't I do this?




-- 
--
Scott Trudeau
scott.trudeau AT gmail DOT com
http://sstrudeau.com/
AIM: sodthestreets


[jQuery] Re: Loading dynamic JS libraries with jQuery

2008-01-15 Thread Nazgulled

I replaced the function with this:

function loadJavascript(scriptFile) {
var scriptsPath;

// Builds the correct scripts path
scriptsPath = $('script').attr('src');
scriptsPath = scriptsPath.replace(/\w+\.js$/, '');

$.getScript(scriptsPath + scriptFile + .js);
}

But it still doesn't work...

On Jan 15, 11:29 pm, Scott Trudeau [EMAIL PROTECTED] wrote:
 Look at $.getScript:

 http://docs.jquery.com/Ajax/jQuery.getScript

 Try something like:

 $(document).ready(function() {
   $.getScript('script/jquery.form.js');

 });

 You can wrap $.getScript in your function to do the script path prepend and
 .js append. No need to do all the messy DOM stuff yourself. That's what
 jQuery is for. ;)

 Scott

 On Jan 15, 2008 6:20 PM, Nazgulled [EMAIL PROTECTED] wrote:





  Hi,
  I'm trying to load JS files (libraries) dynamically at run-time with
  jQuery but I'm not being able to... I thought I had this working
  before but now it's not. Here's my code:

  INDEX.HTML
  html
  head
  script type=text/javascript src=scripts/jquery.js/script
  script type=text/javascript src=scripts/global.js/script
  /head
  body
  /body
  /html

  GLOBAL.JS
  function loadJavascript(scriptFile) {
 var scriptsPath;

 // Builds the correct scripts path
 scriptsPath = $('script').attr('src');
 scriptsPath = scriptsPath.replace(/\w+\.js$/, '');

 // Creates the script element and appends it to the head
 $(document.createElement('script'))
 .attr('src',  scriptsPath + scriptFile + .js)
 .attr('type', 'text/javascript')
 .appendTo('head');
  }

  $(document).ready(function() {
 // Dynamically loads a list of javascript files
 loadJavascript('jquery.form');
  }

  It should have created a script element like this:
  script type=text/javascript src=scripts/jquery.form.js/script
  And appended it to the head element, but it didn't work...

  I'm using the latest jQuery v1.2.2. Hope someone can clarify this to
  me... Why can't I do this?

 --
 --
 Scott Trudeau
 scott.trudeau AT gmail DOT comhttp://sstrudeau.com/
 AIM: sodthestreets


[jQuery] Re: Loading dynamic JS libraries with jQuery

2008-01-15 Thread Morgan Allen
.getScript()?

On Jan 15, 2008 3:20 PM, Nazgulled [EMAIL PROTECTED] wrote:


 Hi,
 I'm trying to load JS files (libraries) dynamically at run-time with
 jQuery but I'm not being able to... I thought I had this working
 before but now it's not. Here's my code:

 INDEX.HTML
 html
 head
 script type=text/javascript src=scripts/jquery.js/script
 script type=text/javascript src=scripts/global.js/script
 /head
 body
 /body
 /html

 GLOBAL.JS
 function loadJavascript(scriptFile) {
var scriptsPath;

// Builds the correct scripts path
scriptsPath = $('script').attr('src');
scriptsPath = scriptsPath.replace(/\w+\.js$/, '');

// Creates the script element and appends it to the head
$(document.createElement('script'))
.attr('src',  scriptsPath + scriptFile + .js)
.attr('type', 'text/javascript')
.appendTo('head');
 }

 $(document).ready(function() {
// Dynamically loads a list of javascript files
loadJavascript('jquery.form');
 }

 It should have created a script element like this:
 script type=text/javascript src=scripts/jquery.form.js/script
 And appended it to the head element, but it didn't work...

 I'm using the latest jQuery v1.2.2. Hope someone can clarify this to
 me... Why can't I do this?




-- 
http://morglog.alleycatracing.com
Lets make up more accronyms!

http://www.alleycatracing.com
LTABOTIIOFR! ROFL! ROFL! ROFL!
Upcoming alley cats, reviews, touring logs, and a general congregation of
bike nerdity.


[jQuery] Re: Loading dynamic JS libraries with jQuery

2008-01-15 Thread Jeroen
On Jan 16, 2008 12:20 AM, Nazgulled [EMAIL PROTECTED] wrote:


 Hi,
 I'm trying to load JS files (libraries) dynamically at run-time with
 jQuery but I'm not being able to...


AFAIK browsers do not support loading external JS after the DOM has loaded.
I think this is the reason for the $.getScript(script.js, function(){ do
stuff...   }); function.

I use this in my projects and it works great and is a much cleaner
alternative. You could
even bind it to an event so it only get's loaded after the event is
triggered (very cool).

-- 
Jeroen


[jQuery] Re: Loading dynamic JS libraries with jQuery

2008-01-15 Thread Nazgulled

Any hints why $.getScript() is not working as it should?

On Jan 15, 11:28 pm, Jeroen [EMAIL PROTECTED] wrote:
 On Jan 16, 2008 12:20 AM, Nazgulled [EMAIL PROTECTED] wrote:



  Hi,
  I'm trying to load JS files (libraries) dynamically at run-time with
  jQuery but I'm not being able to...

 AFAIK browsers do not support loading external JS after the DOM has loaded.
 I think this is the reason for the $.getScript(script.js, function(){ do
 stuff...   }); function.

 I use this in my projects and it works great and is a much cleaner
 alternative. You could
 even bind it to an event so it only get's loaded after the event is
 triggered (very cool).

 --
 Jeroen


[jQuery] Re: Loading dynamic JS libraries with jQuery

2008-01-15 Thread Christof Donat

Hi,

 I'm trying to load JS files (libraries) dynamically at run-time with
 jQuery but I'm not being able to... I thought I had this working
 before but now it's not. Here's my code:

Which Browser are you testing with? Generally there are two possibilities to 
load Scripts dynamically:

1. add a script tag via DOM - loads the script assynchronously. You won't know 
when it has been loaded and some Safari Versions don't execute the script.
2. load the Script with XMLHttpRequest and then eval() it - you can choose 
between synchonous an assynchronous loading. You can provide a callback that 
will get called after the script is loaded. This works with every Browser 
that has a XMLHttpRequest, but will only load scripts from the same Server.

If you whant to have an Example how that could be done, have a look at 
jspax.org.

Christof