简体   繁体   中英

Javascript Window.prototype is undefined

'Window' is undefined error throws if you open a simple html file where you are trying to use the Window object, from IE9. This upper case Window is used in our .NET MVC application to add custom methods to window object. This works perfect with all other browsers and even IE 11. Not sure whether its a browser specific or IIS specific issue.

<head>
    <script>
        alert(Window);
    </script>
</head>
<body/>

The problem here is caused by using uppercased variable name ( Window ). Just use window instead and you are all good.

Also if you just want to add a new method to window, you don't need to use prototype object. You only need prototypal inheritance when creating new objects, which is not typically the case with window .

So putting it together, you can just use:

window.onWindowFocusChanged = function (isWindowFocused) {
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM