仅当可见Internet Explorer开发人员工具栏时,JavaScript脚本才能在Internet Explorer上运行 [英] A JavaScript script only works on Internet Explorer when the Internet Explorer Developer Toolbar is visible

查看:126
本文介绍了仅当可见Internet Explorer开发人员工具栏时,JavaScript脚本才能在Internet Explorer上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以在Firefox 5上运行的脚本,但不能在Internet Explorer 9上运行. 当我打开 Internet Explorer开发人员工具栏插件并尝试与以前相同的操作时,它就可以工作了.页面上还有其他JavaScript代码正在运行,因此只是一部分无效.

I got a script working on Firefox 5 but not with Internet Explorer 9. When I just open the Internet Explorer Developer Toolbar addon and try the same actions as before - it works. There is other JavaScript code on the page which is working, so it is just a part that isn't.

运行时是否有类似开发者工具栏的工具来更改Internet Explorer的任何选项?

Is there something like the developer toolbar changing any options of Internet Explorer while running?

推荐答案

没有引用任何代码,您就不得不猜测.

Without your having quoted any code, one has to guess.

我的猜测是您在代码中使用了console.log(或其他console方法之一).在IE8和IE9上,除非/除非打开开发人员工具,否则console对象不存在.奇怪但真实.

My guess is that you're using console.log (or one of the other console methods) in your code. On IE8 and IE9, the console object doesn't exist until/unless the developer tools are open. Strange but true.

在未打开开发工具的情况下,应该出现"console未定义"的脚本错误.

You should be getting script errors along the lines of "console is undefined" when you don't have the dev tools open.

因此,并且由于console并非在所有浏览器中都存在(肯定不是IE6或IE7,它们仍然占普通浏览用户的18%),因​​此最好不要在生产代码中包含它们或在使用前主动检查console是否存在.

Because of this, and because console doesn't exist in every browser (certainly not IE6 or IE7, which still combined make up about 18% of the general browsing users), it's best not to include them in production code or to check proactively that console exists before using it.

这篇关于仅当可见Internet Explorer开发人员工具栏时,JavaScript脚本才能在Internet Explorer上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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