IE6不解析加载的JavaScript文件(由Google托管的Recaptcha) [英] IE6 does not parse the loaded JavaScript file (Recaptcha hosted by Google)

查看:93
本文介绍了IE6不解析加载的JavaScript文件(由Google托管的Recaptcha)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常奇怪的问题,我正在尝试在网站上使用Recaptcha,它适用于除IE6之外的所有测试浏览器。

This is a really strange issue, I am trying to use the Recaptcha on one of the website, and it works for all browsers tested except for IE6.

I已经参考了谷歌的js:
http:// www .google.com / recaptcha / api / challenge?k = the_key
并根据fiddler2& 'onreadystatechange'事件(有一个readystate =='loaded')

I have made a reference to the google's js: http://www.google.com/recaptcha/api/challenge?k=the_key and it is loaded according to fiddler2 & the 'onreadystatechange' event (which have a readystate == 'loaded')

正常的工作流应该是已经解析的已加载的JS,并且已经请求了另一个js,然后从谷歌加载的图像。我的问题是第一个加载的JS文件(内容类似于下面):

The normal work flow should be the loaded JS been parsed, and another js been requested, then the image loaded from google. my problem is that the first loaded JS file (content similar to below):

var RecaptchaState = {
    site : 'xxxxxxxxxxxx',
    challenge : 'xxxxxxxxxxxxxxxxxxxxxxxxx',
    is_incorrect : false,
    programming_error : '',
    error_message : '',
    server : 'http://www.google.com/recaptcha/api/',
    timeout : 18000
};

document.write('<scr'+'ipt type="text/javascript" s'+'rc="' + RecaptchaState.server + 'js/recaptcha.js"></scr'+'ipt>');

未解析。首先,以下JS测试:

is not parsed. First, the following JS test:

 typeof RecaptchaState == 'undefined'

其次,没有第二个脚本请求(根据fiddler2),更不用说重新搜索图像......

Secondly, there is no second script request (according to fiddler2), not to say the recaptcha image...

在recaptcha标记之后,脚本标记放在体内,我甚至试图动态加载JS:

The script tag is put inside the body, after the recaptcha markups, and I have even tried to load the JS dynamically:

function GetJavaScript(url, callback) {
    var script = document.createElement('script');
    script.src = url;
    var head = document.getElementsByTagName('head')[0];
    var done = false;

    // Attach handlers for all browsers
    script.onload = script.onreadystatechange = function () {
        if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
            done = true;
            callback();

            // remove the hanlder
            script.onload = script.onreadystatechange = null;
            head.removeChild(script);
        }
    };

    head.appendChild(script);
}

给出了相同的行为......最让我困惑的是:
仅当页面从另一页面重定向时,偶尔会出现此问题。 (直接在新的浏览器窗口中打开网址或刷新页面总是工作正常,但使用JavaScript刷新页面不起作用...)

which gives same behaviour... what confuses me most is: this issue occurs occasionally only when the page is redirectly from another page. (open the url directly in new browser window or refresh the page always works fine, however refresh page using JavaScript does not work...)

请帮助,任何建议和/或者想法会受到赞赏...

Please help, any advice and/or idea would be appreciated...

推荐答案

这不是解决办法,只是一种解决方法。

This is not a solve, just an workaround.

请求第一个js文件: http:/服务器站点上的/www.google.com/recaptcha/api/challenge?k=the_key
,并直接在页面上注入脚本的第一部分:

Request the first js file: http://www.google.com/recaptcha/api/challenge?k=the_key on the server site, and inject the first part of the script on the page directly:

var RecaptchaState = {
    site : 'xxxxxxxxxxxx',
    challenge : 'xxxxxxxxxxxxxxxxxxxxxxxxx',
    is_incorrect : false,
    programming_error : '',
    error_message : '',
    server : 'http://www.google.com/recaptcha/api/',
    timeout : 18000
};

然后,使用GetJavaScript函数和/或JQuery.getScript()函数加载第二个脚本:
http://www.google.com/recaptcha/api/ js / recaptcha.js

Then, using the GetJavaScript function and/or JQuery.getScript() function to load the second script: http://www.google.com/recaptcha/api/js/recaptcha.js

此解决方案适用于基于我的测试的IE6,为了减轻服务器负载,我在服务器端检测用户的浏览器以及客户端注入不同的逻辑。

This solution works for IE6 based on my test, and to make the server less load, I detect the user's browser at server end as well as client end to inject different logic.

我知道这是一个肮脏的解决方法,以防这可能对某人有帮助。

I know this is dirty workaround, just in case this might help someone.

这篇关于IE6不解析加载的JavaScript文件(由Google托管的Recaptcha)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆