使用内置服务获取以下信息:
1.获取屏幕高度
2.获取屏幕宽度
3.获取页面title
4.获取url协议
5.获取url主机
6.获取端口号
7.获取url的hash部分
8.获取访问地址,即url地址
其他要求:
1.高度和宽度打开页面2秒后显示出来
2.title,协议,主机在打开页面3秒后显示出来
3.端口号,url地址在打开页面5秒后,弹出提示框询问是否显示,若点击是,则展示出来,否则不展示
源码:
<!doctype html><html><head> <meta charset="utf-8"> <script type="text/javascript" src="angular-1.3.0.js"></script> <title>day12日考</title></head><body ng-app="myapp"><p ng-controller="myctrl"> <p>屏幕有效的宽度(单位:像素):{{ width }}</p> <p>屏幕有效的高度(单位:像素):{{ height }}</p> <p>页面title:{{ title }}</p> <p>url主机:{{ host }}</p> <p>url协议:{{ protocol }}</p> <p>端口:{{ port }}</p> <p>url的hash部分:{{ hash }}</p> <p>url地址:{{ href }}</p></p><script> var nowtime = function () { return new date().tolocaledatestring() + + new date().tolocaletimestring(); }; var app = angular.module(myapp, []); app.controller(myctrl, function ($scope, $interval, $timeout) { $interval(function () { $scope.width = screen.availwidth; $scope.height = screen.availheight; }, 2000); $timeout(function () { $scope.title = document.title; $scope.host = location.host; $scope.protocol = location.protocol; }, 3000); $timeout(function () { var msg = 是否显示?; if (confirm(msg)==true){ $scope.port = window.location.port; $scope.hash = location.hash; $scope.href = window.location.href; }else{ alert(你选择了不展示); } }, 5000); });</script></body></html>
以上就是angular中获取内置服务获取本机的信息的方法的详细内容。