简体   繁体   English

Javascript Window.prototype未定义

[英]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. 如果您从IE9中打开一个试图在其中使用Window对象的简单html文件,则会抛出“ Window”未定义错误。 This upper case Window is used in our .NET MVC application to add custom methods to window object. 在我们的.NET MVC应用程序中,使用了这种大写的Window来向窗口对象添加自定义方法。 This works perfect with all other browsers and even IE 11. Not sure whether its a browser specific or IIS specific issue. 这可以与所有其他浏览器甚至IE 11完美配合。不确定是特定于浏览器还是特定于IIS的问题。

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

The problem here is caused by using uppercased variable name ( Window ). 这里的问题是由使用大写的变量名( Window )引起的。 Just use window instead and you are all good. 只需使用window即可,一切都很好。

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 . 创建新对象时只需要原型继承,而window则通常不是这种情况。

So putting it together, you can just use: 因此,将其放在一起,您可以使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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