我使用 iframe 显示内容,使用带 ionic 框架的 angularjs。在这里,我需要给窗口高度作为 iframe 高度,所以我使用了
$scope.iframeHeight = window.innerHeight;
但是,我只得到 1/4 屏幕。
这是我到目前为止尝试过的。
index.html
<!DOCTYPE html>
<html ng-app="ionicApp">
<head>
<!-- ionic/angularjs CSS -->
<link href="css/ionic.css" rel="stylesheet">
<link href="css/ionic-custom.css" rel="stylesheet">
<!-- ionic/angularjs js bundle -->
<script type="text/javascript" src="js/ionic.bundle.js"></script>
<script>
angular.module('ionicApp', ['ionic'])
.controller('MainCtrl', function($scope) {
$scope.iframeHeight = window.innerHeight;
});
</script>
</head>
<body ng-controller="MainCtrl">
<iframe src="http://stackoverflow.com" ng-style="{height:iFrameHeight}" id="iframeid" width="100%" ></iframe>
</body>
</html>
我错过了什么吗?
最佳答案
主要问题:您需要将“px”单位添加到 window.innerHeight
数字。第二个,变量名是 iframeHeight
而不是 iFrameHeight
。固定表达式将如下所示:
ng-style="{height: iframeHeight + 'px'}"
关于javascript - 如何在angular js中获取窗口高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28713598/