IE7 未加载 JavaScript 文件
IE7 not loading javascript files
互联网上有很多关于这个问题的信息,但是我找不到与此非常具体的东西。
我一直在用新的欧盟cookie法律信息(javascript)更新网站。我刚刚注意到 ie7 没有加载 javascript 文件。已测试警报,但未显示。
脚本包括:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="cookiesJs/jquery.cookie.js"></script>
<script src="cookiesJs/c.js"></script>
c.js:
document.write('<style type="text/css">a{text-decoration: none;}#cookieMessage {font-family: Arial, Helvetica, sans-serif;color: #222;background-color: #D1D3D4;padding: 8px;height: auto;position: fixed;width:200px;margin: 0px 0px 0 0;bottom:0px;right:10px;border:#FFF 2px solid;border-bottom:0px;padding: 0px 8px 8px 8px;-moz-border-radius-topleft: 8px;-moz-border-radius-topright: 8px;-webkit-border-top-left-radius: 8px;-webkit-border-top-right-radius: 8px;border-top-right-radius: 8px;border-top-left-radius: 8px;text-align:left;overflow:hidden;z-index:999999;}#cookieMessage h6 {font-size: 14px;text-transform: uppercase;padding: 0px;margin-top: 8px;margin-right: 0px;margin-bottom: 5px;margin-left: 0px;color: #222;}#cookieMessage img {border:0px;}#cookieMessage p {text-align: left;font-size: 11px;padding: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 2px;margin-left: 0px;color: #222;}#cookieMessage p a {color: #333;}#cookieMessage h6 a {color: #333;text-decoration: none;}#arrow{margin-top: -20px;}</style>');
$(document).ready(function(){
$("#polup").toggle(function(){
$("#cookieMessage").animate({height:120},500);
$("#arrow").animate({height:0},160);
},function(){
$("#cookieMessage").animate({height:22},500);
$("#arrow").animate({height:14},160);
});
});
var accepted = get_cookie("accepted");
if(accepted == null){
document.cookie = "accepted=no; path=/"; // initialize the cookie
}
function accept(){
// when the client clicks accept
$("#cookieMessage").fadeOut();
$.cookie("accepted", "yes", {
expires : 360, //expires in 10 days
path : '/', //The value of the path attribute of the cookie
});
}
function get_cookie ( cookie_name )
// method to retrieve a cookie based upon its name entered
{
var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
if ( results )
return ( unescape ( results[2] ) );
else
return null;
}
var x = get_cookie("consentCookie");
if(x == null){
document.cookie = "consentCookie=yes; path=/";
location.reload();
}var x = get_cookie("consentCookie");
if((x == "yes") && (accepted == "no")){
//if the cookie does not exist it is the users first time on the page
document.cookie = "consentCookie=no; path=/";
var policy = '<div id="cookieMessage"><h6>Cookie Policy</h6><p>Our website uses cookies. By using our website and agreeing to this policy, you consent to our use of cookies.<a href="cookie_policy.htm">Find out more about cookies.</a></p><p><a href="#" onclick="accept();"><img src="cookiesJs/cookieimg/cookie.gif" width="20" height="20" alt="cookie" style="margin-bottom:-5px;" /> I accept</a></p></div>';
document.write(policy);
}else if((x == "no") && (accepted == "no")){
// if they have visited before but not accepted
document.write('<div id="cookieMessage">');
var policy = '<a href="#_" id="polup"><h6>Cookie Policy</h6> <img id="arrow" align="right" src="cookiesJs/cookieimg/arrow.gif" width="18" height="14" alt="arrow" /></a></h6>';
document.write(policy);
document.write('<p>Our website uses cookies. By using our website and agreeing to this policy, you consent to our use of cookies.</p><p><a href="cookie_policy.htm">Find out more about cookies.</a></p><p><a href="#" onclick="accept();"><img src="cookiesJs/cookieimg/cookie.gif" width="20" height="20" alt="cookie" style="margin-bottom:-5px;" /> I accept</a></p></div>');
$("#cookieMessage").css("height","20");
}else{
//if they have visited and accepted
document.write('<div id="cookieMessage" style="display: none"><h6>Cookie Policy</h6></div>');
}
我不明白为什么IE不加载文件。
尾
随逗号
path : '/', //The value of the path attribute of the cookie
删除尾随逗号,魔法应该会发生,你的代码应该可以工作。
可能是编译问题:
你有一行是这样说的:
}var x = get_cookie("consentCookie");
看起来像复制/粘贴问题。
我发现有时IE7会在出现错误时拒绝空白点,而其他浏览器会"尽力而为"并加载/执行他们能做的事情。
相关文章:
- Word文件(Javascript?)中有哪些字符
- 获取二进制数据并将其保存为.mp3文件Javascript
- 创建包含文本内容的新 Google 云端硬盘文件 (javascript)
- 将从 URL 输出的 JSON 保存到文件 javascript
- 单个页面上的多个音频文件javascript
- 将表单数据写入json文件-javascript
- imacros提取两部分数据+连接常量保存到文件javascript
- 检索 XML 文件 (JavaScript)
- 如何将画布图像“data:image/jpeg;base64,.”转换为普通图像文件 - JavaScript
- 用固定的行名称附加文件 javascript
- 打开并读取二进制文件(JavaScript)
- 将 emacs 用于大型多文件 JavaScript 项目
- 加载外部javascript,但HTTP请求重复一个文件javascript
- 从2D数组创建图像文件-JavaScript
- 正在读取文本文件Javascript
- 通过django将STATIC_URL传递到文件javascript
- 从输入文件javascript中获取一些数据
- Django”;静态“;文件-Javascript
- 上传两次相同的图像文件-Javascript
- 从文本文件javascript中读取行/变量