简体   繁体   English

IE6不解析加载的JavaScript文件(由Google托管的Recaptcha)

[英]IE6 does not parse the loaded JavaScript file (Recaptcha hosted by Google)

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. 这是一个非常奇怪的问题,我试图在网站上使用Recaptcha,它适用于除IE6之外的所有测试浏览器。

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: http//www.google.com/recaptcha/api/challenge? k = the_key,它是根据fiddler2和'onreadystatechange'事件加载的(有一个readystate =='装载“)

The normal work flow should be the loaded JS been parsed, and another js been requested, then the image loaded from google. 正常的工作流程应该是已经解析的已加载的JS,并且已经请求了另外的js,然后是从谷歌加载的图像。 my problem is that the first loaded JS file (content similar to below): 我的问题是第一个加载的JS文件(内容类似于下面):

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>');

is not parsed. 没有被解析。 First, the following JS test: 首先,以下JS测试:

 typeof RecaptchaState == 'undefined'

Secondly, there is no second script request (according to fiddler2), not to say the recaptcha image... 其次,没有第二个脚本请求(根据fiddler2),更不用说recaptcha图像......

The script tag is put inside the body, after the recaptcha markups, and I have even tried to load the JS dynamically: 在recaptcha标记之后,脚本标记被放入体内,我甚至尝试动态加载JS:

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);
}

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...) (直接在新浏览器窗口中打开url或刷新页面总是正常工作,但是使用JavaScript刷新页面不起作用...)

Please help, any advice and/or idea would be appreciated... 请帮助,任何建议和/或想法将不胜感激......

Double check that your script's src in the page source isn't api.recaptcha.net (some libraries use that, I know the Java one I was using did). 仔细检查你的脚本在页面源中的src是不是api.recaptcha.net(有些库使用它,我知道我正在使用的Java)。 If it is, that gets forwarded to www.google.com/recaptcha/api, and that seems to cause issues with IE6. 如果是,则会转发到www.google.com/recaptcha/api,这似乎会导致IE6出现问题。 Once I switched to using www.google.com/recaptcha/api as the actual script src, IE6 was completely happy. 一旦我切换到使用www.google.com/recaptcha/api作为实际脚本src,IE6就完全开心了。 Good luck! 祝好运!

我使用https调用解决了这个问题,根据reCaptcha的Google Group中的这个主题。

This is not a solve, just an workaround. 这不是解决方案,只是一种解决方法。

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

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

Then, using the GetJavaScript function and/or JQuery.getScript() function to load the second script: http://www.google.com/recaptcha/api/js/recaptcha.js 然后,使用GetJavaScript函数和/或JQuery.getScript()函数加载第二个脚本: http//www.google.com/recaptcha/api/js/recaptcha.js

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. 这个解决方案适用于基于我测试的IE6,为了减轻服务器负载,我在服务器端和客户端检测用户的浏览器以注入不同的逻辑。

I know this is dirty workaround, just in case this might help someone. 我知道这是一个肮脏的解决方法,以防这可能对某人有所帮助。

NOT ANSWER (or is it?):fo_Ok ie6. 不是答案(或者是吗?):fo_Ok ie6。 Seriously, forget it. 说真的,算了吧。 Without this attitude ie6 will live forever. 没有这种态度,ie6将永远存在。 It is like ancient evil spirit which will be alive until someone believe in it. 它就像古代的邪灵一样,直到有人相信它才会活着。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM