为什么JavaScript只在IE中打开开发人员工具后才能工作? [英] Why does JavaScript only work after opening developer tools in IE once?

查看:130
本文介绍了为什么JavaScript只在IE中打开开发人员工具后才能工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IE9 Bug - 只有在打开开发人员工具一次后才能使用JavaScript。

IE9 Bug - JavaScript only works after opening developer tools once.

我们的网站为用户提供免费的pdf下载,它有一个简单的输入密码下载功能。但是,它在Internet Explorer中根本不起作用。

Our site offers free pdf downloads to users, and it has a simple "enter password to download" function. However, it doesn't work at all in Internet Explorer.

您可以在此中亲身体验示例

下载过程为makeuseof。在任何其他浏览器中,它工作正常。在IE中,两个按钮都不起作用。

The download pass is "makeuseof". In any other browser, it works fine. In IE, both buttons do nothing.

我发现最奇怪的事情是,如果用F12打开和关闭开发人员工具栏,它就会突然开始工作。

The most curious thing I've found is that if you open and close the developer toolbar with F12, it all suddenly starts to work.

我们尝试过兼容模式等等,没有任何区别。

We've tried compatibility mode and such, nothing makes a difference.

我如何做这项工作在Internet Explorer中?

How do I make this work in Internet Explorer?

推荐答案

听起来你的javascript中可能有一些调试代码。

It sounds like you might have some debugging code in your javascript.

您所描述的体验是典型的代码,其中包含 console.log()或任何其他控制台功能。

The experience you're describing is typical of code which contain console.log() or any of the other console functionality.

控制台对象仅在打开开发工具栏时激活。在此之前,调用控制台对象将导致报告为 undefined 。打开工具栏后,控制台将存在(即使工具栏随后关闭),因此您的控制台调用将会起作用。

The console object is only activated when the Dev Toolbar is opened. Prior to that, calling the console object will result in it being reported as undefined. After the toolbar has been opened, the console will exist (even if the toolbar is subsequently closed), so your console calls will then work.

有一些解决方案可以这个:

There are a few solutions to this:

最明显的一个是删除对 console 的引用。你不应该在生产代码中留下这样的东西。

The most obvious one is to go through your code removing references to console. You shouldn't be leaving stuff like that in production code anyway.

如果你想保留控制台引用,你可以将它们包装在中if()语句,或者在尝试调用之前检查控制台对象是否存在的其他一些条件。

If you want to keep the console references, you could wrap them in an if() statement, or some other conditional which checks whether the console object exists before trying to call it.

这篇关于为什么JavaScript只在IE中打开开发人员工具后才能工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆