0

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

因此,为了让 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 中,它给出了另一个控制台消息,我无法理解......

任何帮助,将不胜感激。谢谢。

4

2 回答 2

2

将您的代码包装在文档就绪事件中......

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

});
于 2012-07-15T00:13:42.570 回答
0

我已经更改了代码,这是我的最终版本。经过测试并在 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。

于 2012-07-15T00:55:21.567 回答