Looks like we can't reproduce the issue or there's a problem in the test case provided.
-
[4.2.0 beta] Ext.get(window).getHeight() causes JS error
REQUIRED INFORMATION
Ext version tested:
Browser versions tested against:
DOCTYPE tested against:
Description:
- Ext.get(window).getHeight() causes JS error. The same with Ext.fly. Uncaught TypeError: Cannot read property 'defaultView' of undefined
Steps to reproduce the problem:
The result that was expected:
- A window's height and width
The result that occurs instead:
- A JavaScript error occrus
Test Case:
Code:
<!DOCTYPE html>
<html>
<head>
<title>Ext.get(window).getHeight() causes JS error</title>
<link rel="stylesheet" href="../resources/css/ext-all.css" />
<script src="../ext-all-debug.js"></script>
<script>
Ext.onReady(function () {
Ext.create("Ext.button.Button", {
renderTo: Ext.getBody(),
text: "Ext.get(window).getHeight()",
handler: function () {
alert(Ext.get(window).getHeight());
}
});
Ext.create("Ext.button.Button", {
renderTo: Ext.getBody(),
text: "Ext.fly(window).getWidth()",
handler: function () {
alert(Ext.fly(window).getWidth());
}
});
});
</script>
</head>
<body>
</body>
</html>
-
You're looking for
Code:
Ext.dom.Element.getViewSize();
Twitter - @evantrimboli
Former Sencha framework engineer, available for consulting.
As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.
-
Thank you, Evan.
Does it mean that I should not use Ext.fly, Ext.get for a window?
Well, there might be many other useful methods in Ext.dom.Element API. For example, I see that @Animal used the on method here (I see it is an old post, but anyway):
http://www.sencha.com/forum/showthre...624#post507705
-
Windows can have events, but not dimensions.
Twitter - @evantrimboli
Former Sencha framework engineer, available for consulting.
As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.
-
Well, the method that you suggested
Code:
Ext.dom.Element.getViewSize();
use the getViewportWidth and getViewportHeight methods.
They are:
Code:
/**
* Retrieves the viewport height of the window.
* @static
* @return {Number} viewportHeight
*/
getViewportHeight: function(){
return window.innerHeight;
},
/**
* Retrieves the viewport width of the window.
* @static
* @return {Number} viewportWidth
*/
getViewportWidth: function() {
return window.innerWidth;
}
Does it not return a window's dimensions?
-
Ok, perhaps that was a bad example. My point is that the window API is different from other elements, so you'd need to conditionalize every Element method to check if the element is a window.
Twitter - @evantrimboli
Former Sencha framework engineer, available for consulting.
As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.
-