简单JavaScript/jQuery不工作

简单JavaScript/jQuery不工作,javascript,jquery,internet-explorer,google-chrome-frame,Javascript,Jquery,Internet Explorer,Google Chrome Frame,我可能错过了什么大事,但我已经试了好几个小时了 因此,为了让IE 8及以下版本的用户安装,我尝试了提供的GCF install JS文件,但我更喜欢自己的实现——GCFInstall JS将允许弹出窗口在每个会话中仅打开一次,即使第二次通过按钮调用。如果你第二次打开它,唯一的方法是不让你关闭它 下面是我在页面上的代码: HTML: 是的,就是这么简单。jQuery通常工作得很好:( IE确实显示了“页面上的错误”,但当我点击它时,消息显示了一个令人困惑的错误,我无法理解它的意思 我把代码放进了C

我可能错过了什么大事,但我已经试了好几个小时了

因此,为了让IE 8及以下版本的用户安装,我尝试了提供的GCF install JS文件,但我更喜欢自己的实现——GCFInstall JS将允许弹出窗口在每个会话中仅打开一次,即使第二次通过按钮调用。如果你第二次打开它,唯一的方法是不让你关闭它

下面是我在页面上的代码:

HTML:

是的,就是这么简单。jQuery通常工作得很好:(

IE确实显示了“页面上的错误”,但当我点击它时,消息显示了一个令人困惑的错误,我无法理解它的意思

我把代码放进了Chrome,它给了我另一个控制台信息,我无法理解


如果您有任何帮助,我们将不胜感激。谢谢。

将您的代码包装到一个文档就绪事件中

$(document).ready(function () {

    $("#gcfdl").click(function(){
        var wants_normal_installation = confirm("You will now be taken to google.com/chromeframe where Google Chrome Frame will be activated. Please wait about 10 seconds after clicking Accept and Install, and you will automatically be taken back to this page. Press OK for normal installation (recommended), or Cancel for single-user installation (use if you don't have administrator rights on your computer):");
        if(wants_normal_installation){
            window.location("http://www.google.com/chromeframe?redirect=true");
        }
        else{
            window.location("http://www.google.com/chromeframe?user=true&redirect=true");
        }
    });

});

我已经更改了代码,这是我的最终版本。在IE8中测试并运行,因此没有理由不在IE7中运行。它将页面放入iframe中,这样用户就不会离开网站。请在您的网站上随意使用它。(在此之前,请确保页面上的某个地方有jQuery)


将其放在/resources/js/getgcf.js中:

$("#gcfdl").click(function(){
    var wants_normal_installation = confirm("You will now be taken to google.com/chromeframe where Google Chrome Frame will be activated. Please wait about 10 seconds after clicking Accept and Install, and you will automatically be taken back to this page. Press OK for normal installation (recommended), or Cancel for single-user installation (use if you don't have administrator rights on your computer):");
    if(wants_normal_installation){
        window.location("http://www.google.com/chromeframe?redirect=true");
    }
    else{
        window.location("http://www.google.com/chromeframe?user=true&redirect=true");
    }
});
$(document).ready(function(){
    $("#gcfdl").click(function(){
        var wants_normal_installation = confirm("Press OK for normal installation (recommended), or Cancel for single-user installation (use if you don't have administrator rights on your computer):");
        if(wants_normal_installation){
            $("#gcfdl2").html("&nbsp;<b>When you see that the installation is complete <a href=''>click here</a></b>");
            $("#gcfiframe").html("<iframe height=400 width='100%' src='http://www.google.com/chromeframe'></iframe>");
        }
        else{
            $("#gcfdl2").html("&nbsp;<b>When you see that the installation is complete <a href=''>click here</a></b>");
            $("#gcfiframe").html("<iframe height=400 width='100%' src='http://www.google.com/chromeframe?user=true'></iframe>");
        }
    });
});
$(文档).ready(函数(){
$(“#gcfdl”)。单击(函数(){
var希望_normal_installation=confirm(“按OK进行正常安装(推荐),或按Cancel进行单用户安装(如果您的计算机上没有管理员权限,请使用):”;
如果(需要正常安装){
$(“#gcfdl2”).html(“当您看到安装完成时”);
$(“#gcfiframe”).html(“”);
}
否则{
$(“#gcfdl2”).html(“当您看到安装完成时”);
$(“#gcfiframe”).html(“”);
}
});
});

更改
src=http://www.google.com/chromeframe“
src=”http://www.google.com/chromeframe/eula.html“
跳过第一页直接进入EULA。

你能给出错误消息吗?@doniyor oops似乎不再在IE上出现了-它只是在我将脚本放入HTML时出现的(
此处脚本
),而不是外部保存。Chrome的错误:
事件处理程序中“未定义”的错误:INDEX\u SIZE\u ERR:DOM Exception 1未定义
这里工作正常:您能帮我们重现您的问题吗?@MartinAmps有趣…如果您想拥有look@duncan12我也没有得到任何错误,但我没有IE的te现在恐怕不行。如果你到那时还没有解决它,我明天会在IE上检查。谢谢!我以为document ready只对你需要在启动时运行的东西有用,而且当有人点击按钮时,文档一定已经准备好了,所以不需要了。但显然我被误导了。顺便说一句,我不得不更改
window.location
window.location.replace
以使第二部分正常工作。有人能解释一下为什么我错了吗(我认为当有人单击按钮时文档就准备好了,这里不需要准备doment的东西)当时jQuery函数$(“#gcfdl”)运行它尝试查找它并绑定单击事件处理程序。如果找不到元素,则不会附加单击处理程序。您可以使用jQuery函数delegate(),但在您的情况下,我建议使用document ready。
<!--[if lt IE 9]><script type="text/javascript" src="/resources/js/getgcf.js"></script>
<div style="border:1px solid black; padding: 3px;"><img src="http://cdn.dustball.com/information.png" alt="info"> You appear to be using an older version of Internet Explorer. This website relies on technology not supported by Internet Explorer. To improve your experience (and fix layout errors):
<br><button id="gcfdl">Activate Google Chrome Frame</button><span id="gcfdl2"></span><div id="gcfiframe"></div><br>You won't notice anything different in the way you use the internet, except that most websites will look better.</div><![endif]-->
$(document).ready(function(){
    $("#gcfdl").click(function(){
        var wants_normal_installation = confirm("Press OK for normal installation (recommended), or Cancel for single-user installation (use if you don't have administrator rights on your computer):");
        if(wants_normal_installation){
            $("#gcfdl2").html("&nbsp;<b>When you see that the installation is complete <a href=''>click here</a></b>");
            $("#gcfiframe").html("<iframe height=400 width='100%' src='http://www.google.com/chromeframe'></iframe>");
        }
        else{
            $("#gcfdl2").html("&nbsp;<b>When you see that the installation is complete <a href=''>click here</a></b>");
            $("#gcfiframe").html("<iframe height=400 width='100%' src='http://www.google.com/chromeframe?user=true'></iframe>");
        }
    });
});