L84*_*L84 8 javascript jquery internet-explorer jquery-plugins colorbox
我找到了一个解决方案,但它不是最好的,所以我仍在寻找解决方案.看看我的答案.
更新 - 我的错误仍然存在,如下所述,但如果我打开IE的开发人员工具,错误就会消失!如果我关闭浏览器并重新打开错误重新出现!
更新2 - 我试图将以下代码插入到我的JS中,看看是否可以解决问题但它没有:
if (!("console" in window) || !("firebug" in console)) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0, len = names.length; i < len; ++i) {
window.console[names[i]] = function(){};
}
}
Run Code Online (Sandbox Code Playgroud)
然后这个:
var console = {};
console.log = function(){};
Run Code Online (Sandbox Code Playgroud)
我还扫描了我的JS文件,并且从未遇到导致错误的console.log函数.
这是一个令人费解的问题,我会尽力解释.我在一个页面中设置cookie,在第一次访问时会显示一个灯箱.它在FF,Chrome等中运行良好,但在IE中却不行.
在IE中发生的是用于调用我的灯箱(彩盒)的脚本,但我看到的是AJAX Loader正在旋转并且内容永远不会加载.我发现剧本太快了.我正在使用$j(document).ready(function()我切换到:$j(window).load(function()所有似乎都很好,它工作正常,直到我从另一页开始,来到上面提到的页面.
如果我从任何其他页面开始并单击链接我有同样的问题!cookie工作正常,不会再次激活盒子.
换句话说,如果我清除cookie并从问题页面开始那么没问题.但是,如果我从任何其他页面开始(清除了cookie)并转到上面的页面,则颜色框无法正确加载.
据我所知,这$j(window).load(function()是行不通的.
我从IE收到没有错误.我正在使用IE 8进行测试,因为我使用的是Windows XP,所以无法测试9.(我被告知它在IE 9中工作正常,但尚未证实这一点)脚本在<head>我的文档中.(如果我将脚本移动到<body>它完全打破页面.)
我已经阅读DOCTYPE过IE 中不正确或短缺以及彩盒问题.我的DOCTYPE如下,应该是正确的:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Run Code Online (Sandbox Code Playgroud)
任何想法或想法都非常感谢!
这是我正在使用的代码:
使用Javascript
var $j = jQuery.noConflict();
$j(window).load(function() {
//window.onload = function() does not function properly either...
if(!$j.cookie('gallerycookie')){
$j.colorbox({
inline:true,
href:"#gallery-nav-instruct"
});
$j.cookie("gallerycookie", 1, {
expires: 30,
path: '/'
});
}
});
Run Code Online (Sandbox Code Playgroud)
HTML
<div style="display:none">
<div id="gallery-nav-instruct">
<h2>Gallery Navigation Instructions - Step 1</h2><h2 style="text-align:right">
<a style="text-align:right;" class="inline cw" href="
#gallery-enlarge-instruct">Step 2</a></h2>
<p> </p>
<p class="white"><img src="/Images/Pages/gallery-navigation.jpg" width="890" height="450" alt="Gallery Navigation Instructions" /></p>
</div>
</div>
<div style="display:none">
<div id="gallery-enlarge-instruct">
<h2>Gallery Navigation Instructions - Step 2</h2>
<p> </p>
<h2><a class="inline cw" href="#gallery-nav-instruct">Step 1</a> </h2>
<p class="white"><img src="/Images/Pages/gallery-enlarge.jpg" width="890" height="510" alt="Gallery -Enlarged View Instructions" /></p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
另一个注意事项:我在页面上使用jAlbum,我没有看到任何冲突,但可能有问题吗?我不能在这里发布该代码,因为它会超过SO的帖子限制.
要从此页面开始触发此错误,将出现一个灯箱.单击Message Examples(灯箱的左下角或菜单中没有灯箱的第一项).
如果需要,这是指向该页面的直接链接.(直接转到页面不会触发错误.)
我试图使用window.onload = function(),同样的问题发生了.
我尝试使用事件处理程序在加载div后触发脚本,甚至根本不触发脚本.这是代码:
var $j = jQuery.noConflict();
$j('#gallery-nav-instruct').load(function() {
if(!$j.cookie('gallerycookie')){
$j.colorbox({
inline:true,
href:"#gallery-nav-instruct"
});
$j.cookie("gallerycookie", 1, {
expires: 30,
path: '/'
});
}
});
Run Code Online (Sandbox Code Playgroud)
打开开发人员工具时它消失的原因是IE在任何console.log语句中都不能很好地运行,直到您打开开发人员工具.某处必须有console.log.它可以在您正在使用的任何插件文件或javascript文件中.由于某种原因,它会杀死之后运行的javascript.打开开发人员工具将console.log识别为javascript函数(我的最佳猜测),因此它突然起作用.
| 归档时间: |
|
| 查看次数: |
5148 次 |
| 最近记录: |