最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Problems with Extjs.getBody - Stack Overflow

programmeradmin1浏览0评论

I have this line of code

 var width_client = Ext.getBody().getWidth(true);

and I get that Ext.getBody() is null. I asume that this check is doen before Ext.getBody() becames not null, but dont' know were or what to change.

Any idea how to solve this?

I use extjs 4.0.7

I have this line of code

 var width_client = Ext.getBody().getWidth(true);

and I get that Ext.getBody() is null. I asume that this check is doen before Ext.getBody() becames not null, but dont' know were or what to change.

Any idea how to solve this?

I use extjs 4.0.7

Share Improve this question asked Jul 2, 2012 at 14:40 VladVlad 2,7737 gold badges52 silver badges106 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You can access document.body when it is rendered. From your question I made a conclusion that your code was located inside <head>. When this code is executed there is no <body> rendered yet. You have to wrap your code by a function and pass this function to Ext.onReady (or Ext.onDocumentReady) method:

Ext.onReady(function() {
    alert(Ext.getBody().getWidth(true));
});

Here is demo.

You have to wait until the page is loaded and ready. Try this.

Ext.onReady(function() { Ext.getBody().getWidth();})
发布评论

评论列表(0)

  1. 暂无评论