简单的JavaScript/jQuery不起作用

Simple JavaScript / jQuery not working

本文关键字:jQuery 不起作用 JavaScript 简单      更新时间:2023-09-26

我可能错过了一些大事,但我已经尝试了几个小时。。。

因此,为了让IE 8及以下版本的用户安装Chrome Frame,我尝试了提供的GCF install JS文件,但我更喜欢自己的实现——GCFInstall JS会让弹出窗口在每个会话中只打开一次,即使第二次被按钮调用也是如此。我找到的唯一解决方案是,如果你第二次打开它,就不会让你关闭它。

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

HTML:

<!--[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><br>You won't notice anything different in the way you use the internet, except that most websites will look better.</div><![endif]-->

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

是的,就这么简单。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)

<!--[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]-->

将其作为/resources/js/getgcf.js:

$(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>");
        }
    });
});

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