IE9 Bug - JavaScript只能在打开一次开发工具后才能工作。

我们的网站为用户提供免费的pdf下载,它有一个简单的“输入密码下载”功能。但是,它在ie浏览器中完全不起作用。

你可以在这个例子中看到。

下载通道是“makeuseof”。在任何其他浏览器中,它都可以正常工作。在IE中,两个按钮什么都不做。

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

我们已经尝试了兼容模式等,没有什么不同。

我如何使这工作在Internet Explorer?


当前回答

对我来说,这发生在IE 11中。我在调用jquery。load函数。 所以我用了老方法,在url中放了一些东西来禁用缓存。

$("#divToReplaceHtml").load('@Url.Action("Action", "Controller")/' + @Model.ID + "?nocache=" + new Date().getTime());

其他回答

我把解决方案和解决我的问题。看起来像AJAX请求,我把我的JavaScript没有处理,因为我的页面有一些缓存问题。如果你的站点或页面有缓存问题,在开发者/F12模式下你不会看到这个问题。我缓存的JavaScript AJAX请求,它可能不会像预期的那样工作,并导致执行中断,其中F12没有任何问题。 添加新参数使cache为false。

$.ajax({
  cache: false,
});

看起来IE特别需要这个为假,以便AJAX和javascript活动运行良好。

我们在Windows 7和Windows 10的IE 11上遇到了这个问题。我们通过打开IE的调试功能(IE > Internet Options > Advanced tab > Browsing > Uncheck Disable script debugging (Internet Explorer))来发现问题所在。这个特性通常由域管理员在我们的环境中检查。

The problem was because we were using the console.debug(...) method within our JavaScript code. The assumption made by the developer (me) was I did not want anything written if the client Developer Tools console was not explicitly open. While Chrome and Firefox seemed to agree with this strategy, IE 11 did not like it one bit. By changing all the console.debug(...) statements to console.log(...) statements, we were able to continue to log additional information in the client console and view it when it was open, but otherwise keep it hidden from the typical user.

如果你使用的是angular和ie 9,10或edge:

myModule.config(['$httpProvider', function($httpProvider) {
    //initialize get if not there
    if (!$httpProvider.defaults.headers.get) {
        $httpProvider.defaults.headers.get = {};    
    }    

    // Answer edited to include suggestions from comments
    // because previous version of code introduced browser-related errors

    //disable IE ajax request caching
    $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
    // extra
    $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
    $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
}]);

完全禁用缓存。

对我来说,这发生在IE 11中。我在调用jquery。load函数。 所以我用了老方法,在url中放了一些东西来禁用缓存。

$("#divToReplaceHtml").load('@Url.Action("Action", "Controller")/' + @Model.ID + "?nocache=" + new Date().getTime());

如果你使用的是AngularJS版本1。X你可以使用$log服务,而不是直接使用console.log。

简单的日志服务。默认实现将消息安全地写入浏览器的控制台(如果存在)。

https://docs.angularjs.org/api/ng/service/美元日志

如果你有类似的东西

angular.module('logExample', [])
  .controller('LogController', ['$scope', function($scope) {
    console.log('Hello World!');
 }]);

你可以用

angular.module('logExample', [])
  .controller('LogController', ['$scope', '$log', function($scope, $log) {
    $log.log('Hello World!');
 }]);

Angular 2+没有任何内置的日志服务。