当前位置:   article > 正文

IE8 console未定义_execjs._exceptions.programerror: typeerror: 'conso

execjs._exceptions.programerror: typeerror: 'console' 未定义

写了一个extjs页面,在chrome下调试好好的,在ie8下调试页面打开,进度条没按预期更新。代码如下:

  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <title>ExtJs</title>
  4. <meta charset="GBK">
  5. <link href="ExtJs/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
  6. <script type="text/javascript" src="ExtJs/ext-base.js"></script>
  7. <script type="text/javascript" src="ExtJs/ext-all-debug-w-comments.js"></script>
  8. </head>
  9. <body>
  10. <div>
  11. <script type="text/javascript">
  12. Ext.MessageBox.show({
  13. title: '倒计时提醒',
  14. <span style="white-space:pre"> </span> msg: '这是一个倒计时',
  15. buttons:{"ok":"知道了"},
  16. animEl: 'mb9',
  17. closable : false,
  18. width : 300,
  19. progress : true,
  20. progressText: '5秒后将xxx',
  21. fn: answerPhone
  22. });
  23. var timeLeft = 5;
  24. var countDownTask = {
  25. run:countDownFunc,
  26. interval:1000
  27. };
  28. function countDownFunc(){
  29. console.log("fuck" + timeLeft);
  30. if(timeLeft <= 0){
  31. Ext.MessageBox.updateProgress(1, "倒计时结束");
  32. Ext.MessageBox.buttons = false;
  33. //简单延迟后关闭窗口
  34. setTimeout(function(){Ext.MessageBox.hide()}, 500);
  35. //终止轮询任务
  36. Ext.TaskMgr.stop(countDownTask);
  37. answerPhone();
  38. }
  39. else{
  40. timeLeft--;
  41. Ext.MessageBox.updateProgress((5-timeLeft)/5, timeLeft+'秒之后将xxxx');
  42. }
  43. }
  44. Ext.TaskMgr.start(countDownTask);
  45. var answerPhone = function(){
  46. console.log("倒计时后调用的函数。");
  47. };
  48. </script>
  49. </div>
  50. </body>
  51. </html>


按F12查看控制台信息,发现这么一句"console未定义"。网上查了一下,有两种解决办法


1.注释掉console的语句(好暴力....)

2.但是有时候实在是需要支持console来调试,那么可以加入如下代码

  1. window.console = window.console || (function(){
  2. var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
  3. = c.clear = c.exception = c.trace = c.assert = function(){};
  4. return c;
  5. })();


加入上述片段后,ie8就可以使用console了,修改后的代码

  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <title>ExtJs</title>
  4. <meta charset="GBK">
  5. <link href="ExtJs/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
  6. <script type="text/javascript" src="ExtJs/ext-base.js"></script>
  7. <script type="text/javascript" src="ExtJs/ext-all-debug-w-comments.js"></script>
  8. </head>
  9. <body>
  10. <div>
  11. <script type="text/javascript">
  12. window.console = window.console || (function(){
  13. var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
  14. = c.clear = c.exception = c.trace = c.assert = function(){};
  15. return c;
  16. })();
  17. Ext.MessageBox.show({
  18. title: '倒计时提醒',
  19. msg: '这是一个倒计时',
  20. buttons:{"ok":"知道了"},
  21. animEl: 'mb9',
  22. closable : false,
  23. width : 300,
  24. progress : true,
  25. progressText: '5秒后将xxx',
  26. fn: answerPhone
  27. });
  28. var timeLeft = 5;
  29. var countDownTask = {
  30. run:countDownFunc,
  31. interval:1000
  32. };
  33. function countDownFunc(){
  34. console.log("fuck" + timeLeft);
  35. if(timeLeft <= 0){
  36. Ext.MessageBox.updateProgress(1, "倒计时结束");
  37. Ext.MessageBox.buttons = false;
  38. //简单延迟后关闭窗口
  39. setTimeout(function(){Ext.MessageBox.hide()}, 500);
  40. //终止轮询任务
  41. Ext.TaskMgr.stop(countDownTask);
  42. answerPhone();
  43. }
  44. else{
  45. timeLeft--;
  46. Ext.MessageBox.updateProgress((5-timeLeft)/5, timeLeft+'秒之后将xxxx');
  47. }
  48. }
  49. Ext.TaskMgr.start(countDownTask);
  50. var answerPhone = function(){
  51. console.log("倒计时后调用的函数。");
  52. };
  53. </script>
  54. </div>
  55. </body>
  56. </html>






声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号