Search code examples
javascriptdojoxpagesinternet-explorer-11lotus-domino

dojo.exists fails with IE11


Since a few days, I have troubles with Internet Explorer 11 in conjunction with dojo toolkit 1.9.4 hosted by a Domino Server.

Source Code:


if (dojo.exists("btnUpload")) {
    console.log("btnUpload exist ... do something...");
} else {
    console.log("btnUpload doesn't exist...");
}

With IE11 the return value of dojo.exists() is always false!

IE11 Debugger:


enter image description here

However in all other browser (Mozilla Firefox, Google Chrome, Apple Safari) it works!


Solution

  • Using dojo.exists for this isn't very appropriate, given that btnUpload is technically just a DOM ID, and not an actual object in the global scope. if (document.getElementById('btnUpload')) would seem to be far more appropriate in this case.

    When a global reference is encountered that doesn't match an actual global variable, but does match a DOM ID, browsers tend to return the DOM node, but I wouldn't recommend relying upon that.