Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE9打开页面不显示内容,打开控制台才会加载内容 #161

Open
ly2011 opened this issue Mar 4, 2019 · 0 comments
Open

IE9打开页面不显示内容,打开控制台才会加载内容 #161

ly2011 opened this issue Mar 4, 2019 · 0 comments
Labels

Comments

@ly2011
Copy link
Owner

ly2011 commented Mar 4, 2019

原因

这个问题产生的原因是因为IE不支持console语法,如果语句中有console,只有在控制台打开的时候才会执行代码。

解决方案

有两种解决方案:

方案1
对于使用webpack打包的项目,处理起来就比较简单了,在webpack.conf.js 中,uglifyjsPlugin插件中添加配置项:

uglifyOptions: {
  compress: {
    drop_console:true
  }
}

这样打包之后就会自动删除所有的console;

方案2

在页面头部添加代码,对console进行判断,是否识别:

<script type="text/javascript">
if(!window.console){
    window.console = {};
}
if (!window.console.log) {
    window.console.log = function(mes){ };
}
</script>
@ly2011 ly2011 added the JS label Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant