简体   繁体   English

javascript:window-object未定义

[英]javascript: window-object is undefined

I´m trying to attach the resize-event of the window within an self-developed-jquery-extension. 我试图在自行开发的jquery-extension中附加窗口的resize-event。 It looks like this: 它看起来像这样:

$(window).resize(function ()
{
    this.trigger();
}.bind(this));

I wondered that this event is never triggered and recognized that the window-object is undefined. 我想知道这个事件永远不会被触发并且识别出window-object是未定义的。 But I cannot find any reason why. 但我找不到任何理由。 The extension is in a script-tag of a html-snippet which is loaded via ajax and inserted into the DOM. 扩展名在html-snippet的脚本标记中,该标记通过ajax加载并插入到DOM中。 This extension should be triggered after the document has been completed. 文档完成后应触发此扩展。

<script>
    jQuery(function()
    {
        jQuery('#myId').myExtension();
    });
</script>

I found out at the MDN that the window-object is referenced in the document: 我在MDN上发现文档中引用了window-object:

window.defaultView

So I tried the following: 所以我尝试了以下方法:

document.defaultView.addEventListener('onresize', function ()
{ 
    //...
});

Indeed defaultView has an object but this alternative has also no result! 确实defaultView有一个对象,但这个替代方案也没有结果!

Any ideas? 有任何想法吗?

Problem solved. 问题解决了。 I made a mistake: I declared a variable with the name "window" in a if-block some lines before... I didn´t see that. 我犯了一个错误:我之前在if-block中声明了一个名为“window”的变量......我没有看到。

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

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