<!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>
angularjs服务获取屏幕宽度,url,本机地址...
最新推荐文章于 2023-10-13 14:09:52 发布