angularjs服务获取屏幕宽度,url,本机地址...

来源:互联网 发布:淘宝投诉投诉 编辑:程序博客网 时间:2024/06/01 20:26
<!DOCTYPE html><html ng-app="myapp"><head>    <meta charset="UTF-8">    <title>各种service</title>    <script src="angular-1.3.0.js"></script>    <script>        var my=angular.module("myapp",[]);        my.controller("myCtrl",function($scope,$window,$document,$location){            $scope.wHeight=$window.innerHeight;            $scope.wWidth=$window.innerWidth;            //-------------------------------------------设置title            //$document[0].title="呵呵";            $scope.title=$document[0].title;            $scope.protocol=$location.protocol();//--------URL协议部分            $scope.hostname=$location.host();//------------URL主机部分            $scope.port=$location.port();//----------------端口号            $location.path("aaa");//-----------------------设置URL中的 hash部分            $scope.path=$location.path();            $scope.absUrl=$location.absUrl();//-------------获得URL        })    </script></head><body ng-controller="myCtrl"><p>屏幕高度{{wHeight}}</p><p>屏幕宽度{{wWidth}}</p><p>页面title{{title}}</p><p>获取url协议{{protocol}}</p><p>获取url主机{{hostname}}</p><p>获取端口号{{port}}</p><p>获取hash部分{{path}}</p><p>获取访问地址{{absUrl}}</p></body></html>