Jerry Jäppinen
Jerry Jäppinen

Reputation: 37

JavaScript not running without developer console in IE (can't attribute to missing console)

I'm writing a web application platform that serves JavaScript applications to a browser. Needless to say, I launch an application with a JS method after the document has loaded, but on IE9 nothing happens if the developer console hasn't been fiddled with.

This seems like the typical missing console problem, but I couldn't fix it by adding a check for console or removing console calls from the source code.

Can you guys spot where I'm going wrong?

I'm serving multiple separate web apps with the same platform, so you can also check out the following (the problem appears the same all over):

Upvotes: 1

Views: 210

Answers (1)

lorefnon
lorefnon

Reputation: 13105

Object.keys is not supported in all versions of internet explorer : Please refer to the following : https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys The following (from the source mentioned above) adds Object.keys to the browsers that do not support it :


if (!Object.keys) {
  Object.keys = (function () {
    var hasOwnProperty = Object.prototype.hasOwnProperty,
        hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
        dontEnums = [
          'toString',
          'toLocaleString',
          'valueOf',
          'hasOwnProperty',
          'isPrototypeOf',
          'propertyIsEnumerable',
          'constructor'
        ],
        dontEnumsLength = dontEnums.length

    return function (obj) {
      if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object')

      var result = []

      for (var prop in obj) {
        if (hasOwnProperty.call(obj, prop)) result.push(prop)
      }

      if (hasDontEnumBug) {
        for (var i=0; i 

In addition, your method of checking the existence of console is erroneous :

Try running (http://jsfiddle.net/PytAh/) in internet explorer:

if (console){
    alert("there");
} else {
    alert("not there");
}

It will generate an error showing that console does not exist. You can replace it by :

if (window.console){
    alert("there");
} else {
    alert("not there");
}

Upvotes: 1

Related Questions