AngularJs Get Browser Viewport Dimensions


AngularJs Get Browser Viewport Dimensions : We can get the browser viewport height and width using the JavaScript. Here in this tutorial we are going to explain how you can get the browser Viewport height and width using the JavaScript. You can use our online editor to edit and run the code online.


AngularJs Get Browser Viewport Dimensions Using JavaScript

You can use the following JavaScript to get the browser’s viewport height and width as below-

AngularJs Get Browser Viewport Dimensions :

<!DOCTYPE html>
<html lang="en">
<head>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
 <script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
$scope.height = '';
$scope.width = '';
 $scope.getViewportDim = function() {    
	$scope.height = Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
    $scope.width = Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
 };
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController"> 

 <button ng-click='getViewportDim()' >Get Dim</button><br>
 Height = {{height}}PX<br>
 Width = {{width}}PX<br>

</div> 
</div>
</body>  
</html>      

Try it »

If you run the above example it will produce output something like this –

AngularJs Get Browser Viewport Dimensions


Advertisements

Add Comment

📖 Read More