简体   繁体   English

当开发者工具打开 IE11 时,网站的行为会有所不同

[英]Site behaves differently when developer tools are open IE11

Im using the following template in IE11 and can not figure out why the sidebar sings in every time navigation is happening.我在 IE11 中使用以下模板,但无法弄清楚为什么每次导航发生时侧边栏都会唱歌。 When developer tools are open it behaves as I would like it to.当开发人员工具打开时,它的行为就像我希望的那样。 It is easily demoed by clicking on any one of the tabs under UI element in the tree while running IE11.通过在运行 IE11 时单击树中 UI 元素下的任何选项卡,可以轻松演示。 However you will notice if F12 developer tools are open the side bar does not slide in every time navigation happens.但是,您会注意到,如果 F12 开发人员工具处于打开状态,则侧栏不会在每次导航发生时滑入。 This is not an issue in chrome.这在 chrome 中不是问题。 There is an error with fastclick that may show up however I have ran without fastclick and it still happens.可能会出现 fastclick 错误,但是我在没有 fastclick 的情况下运行,它仍然发生。 Any help would be great.任何帮助都会很棒。 Thanks.谢谢。 https://almsaeedstudio.com/themes/AdminLTE/pages/UI/general.html https://almsaeedstudio.com/themes/AdminLTE/pages/UI/general.html

Try removing any console.log() from your code.尝试从您的代码中删除任何console.log()

console.log() which is to help out when debugging Javascript can cause IE to completely stop processing scripts on the page. console.log()用于帮助调试 Javascript 会导致 IE 完全停止处理页面上的脚本。 To add to the mystery, if you keep watching your page in IE with devtools open - you won't notice an issue at all.更神秘的是,如果您在 IE 中打开 devtools 继续查看您的页面 - 您根本不会注意到任何问题。

Explanation解释

The reason for this is the console object is not instantiated unless devtools is open in IE.原因是控制台对象不会被实例化,除非在 IE 中打开 devtools。 Otherwise, you will see one of two things:否则,您将看到以下两种情况之一:

  1. Javascript won't execute correctly Javascript 无法正确执行
  2. Console has cryptic errors, such as 'object is undefined' or others of that nature控制台有神秘的错误,例如“对象未定义”或其他类似的错误

Nine times out of ten, you have an errant console.log in the code somewhere.十分之九,您在代码中的某个地方有一个错误的 console.log。 This does not affect any browser other than IE.这不会影响除 IE 之外的任何浏览器。

Another potential cause, especially if you are performing ajax calls, is the ajax response may be cached when dev tools are closed, but refreshed from the server when dev tools are open.另一个潜在原因,尤其是在执行 ajax 调用时,可能会在开发工具关闭时缓存 ajax 响应,但在开发工具打开时从服务器刷新。

In IE, open the Network tab of Developer Tools , click the play icon, and un-set the Always refresh from server button.在 IE 中,打开Developer ToolsNetwork选项卡,单击播放图标,然后取消设置Always refresh from server按钮。 Then watch to see if any of your ajax calls are coming back with a response code of 304 (Not modified).然后观察是否有任何 ajax 调用返回响应代码为 304(未修改)。 If they are, then you are not getting fresh data from the server and you need to update the cacheability settings on the page that is being called via ajax.如果是,那么您不会从服务器获取新数据,您需要更新通过 ajax 调用的页面上的可缓存性设置。

Adding onto the already great answers (since I can't comment - requires 50 rep points), agreeing with the answer from @sam100rav and the comment from @storsoc, I discovered that in IE11 version 11.1387.15063.0 with updated version 11.0.90 ( KB4462949 ), that window.console indeed exists as an empty object ( window.console = {} ).添加到已经很好的答案(因为我无法发表评论 - 需要 50 个代表点),同意@sam100rav 的答案和@storsoc 的评论,我发现在 IE11 版本11.1387.15063.0和更新版本11.0.90KB4462949 ),那个window.console确实作为一个空对象存在( window.console = {} )。 Hence, I used a variation of the polyfill from @storsoc as shown below.因此,我使用了来自 @storsoc 的 polyfill 的变体,如下所示。

 if (!window.console || Object.keys(window.console).length === 0) { window.console = { log: function() {}, info: function() {}, error: function() {}, warn: function() {} }; }

As pointed out already it's because IE11 + Edge<=16 is so stupid that it doesn't support console unless developer tools is opened... So if you open that to disable caching you won't see any issues and you might think that the issue was just due to browser cache... but nope.. :@正如已经指出的那样,这是因为 IE11 + Edge<=16 太愚蠢了,除非打开开发人员工具,否则它不支持console ......所以如果你打开它来禁用缓存你不会看到任何问题,你可能会认为问题只是由于浏览器缓存......但不是......:@

I made this "polyfill" for it (doesn't really polyfill, but makes IE not throw any errors).我为它制作了这个“polyfill”(并不是真正的 polyfill,但使 IE 不会抛出任何错误)。 Add it as early as possible on your site as any js might be using console.log or console.warn etc.尽早在您的站点上添加它,因为任何 js 都可能使用console.logconsole.warn等。

window.console = typeof window.console !== 'object' || {};
console.warn = typeof console.warn === 'function' || function () {
  return this;
};
console.log = typeof console.log === 'function' || function () {
  return this;
};
console.info = typeof console.info === 'function' || function () {
  return this;
};
console.error = typeof console.error === 'function' || function () {
  return this;
};
console.assert = typeof console.assert === 'function' || function () {
  return this;
};
console.dir = typeof console.dir === 'function' || function () {
  return this;
};
console.table = typeof console.table === 'function' || function () {
  return this;
};
console.group = typeof console.group === 'function' || function () {
  return this;
};
console.groupEnd = typeof console.groupEnd === 'function' || function () {
  return this;
};
console.time = typeof console.time === 'function' || function () {
  return this;
};
console.timeEnd = typeof console.timeEnd === 'function' || function () {
  return this;
};
console.timeLog = typeof console.timeLog === 'function' || function () {
  return this;
};
console.trace = typeof console.trace === 'function' || function () {
  return this;
};
console.clear = typeof console.clear === 'function' || function () {
  return this;
};
console.count = typeof console.count === 'function' || function () {
  return this;
};
console.debug = typeof console.debug === 'function' || function () {
  return this;
};
console.dirxml = typeof console.dirxml === 'function' || function () {
  return this;
};
console.groupCollapsed = typeof console.groupCollapsed === 'function' || function () {
  return this;
};

I'm assuming you've fixed this since you posted it as I can not see the behavior you describe in your link.我假设你已经解决了这个问题,因为你发布了它,因为我看不到你在链接中描述的行为。

However, I have recently run into a similar issue where the dev tools being open changed the behavior not because of console issues, but because opening the tools changed the width of the window.但是,我最近遇到了一个类似的问题,其中打开的开发工具改变了行为,不是因为控制台问题,而是因为打开工具改变了窗口的宽度 It was the window width difference that triggered an underlying bug in my case.在我的案例中,是窗口宽度差异触发了一个潜在的错误。

Related post here .相关帖子在这里

It's possible you've got the compatibility mode set to a later version of IE in your developer console (see the highlighted section)您可能在开发者控制台中将兼容模式设置为更高版本的 IE(请参阅突出显示的部分) 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM