views:

16

answers:

1

I need to load the Recaptcha library on demand, with javascript (using Prototype):

var captcha = new Element('script', { type: 'text/javascript', src: 'http://api.recaptcha.net/js/recaptcha_ajax.js' });
$$('head')[0].appendChild(captcha);
captcha.onload = function()
{
  Recaptcha.create("dsfahsldkjfhlasdjfc","recaptcha_image", {theme: "custom"});
};

The problem here is with IE, of course. It seems that the captcha.onload wont work in IE. As usual, it works on other browsers. So, how can I check that the script is loaded on IE, and call Recaptcha.create afterwards?

Is there an easier and cross-browser way of loading and evaluating external scripts with Prototype? Thanks.

A: 

Looks like IE doesn't support onload, but DOES support onreadystatechange:

Sample code for onreadystatechange: http://gist.github.com/461797

Post with some info, source of above link:

http://blog.andrewcantino.com/post/211671748/replacement-for-script-onload-in-ie

Andrew M
that helped. thanks.
JoaoPedro