使用 Prototype 加载 Recaptcha 脚本
我需要使用 javascript(使用 Prototype)按需加载 Recaptcha 库:
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"});
};
当然,这里的问题是 IE。看来 captcha.onload
在 IE 中不起作用。像往常一样,它可以在其他浏览器上运行。 那么,如何检查脚本是否已在 IE 上加载,然后调用 Recaptcha.create
?
是否有更简单的跨浏览器方法来使用 Prototype 加载和评估外部脚本? 谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来IE不支持onload,但支持onreadystatechange:
onreadystatechange的示例代码:
http://gist.github.com/461797
发布一些信息,上述链接来源:
http://blog.andrewcantino.com/post/211671748/replacement -for-script-onload-in-ie
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