如何在$ rootscope中设置变量以显示浏览器是否在iPad上运行?(How can I set a variable in $rootscope to show if a browser is

编程入门 行业动态 更新时间:2024-10-24 10:18:53
如何在$ rootscope中设置变量以显示浏览器是否在iPad上运行?(How can I set a variable in $rootscope to show if a browser is running on an iPad?)

我知道有一些库可以做到这一点,但我想做一些尽可能简单的事情,我没有看到任何针对AngularJS应用程序的示例。 问题是我不知道从哪里开始。

有人可以给我一些建议或指出我正确的方向。

I know there are some libraries that can do this but I would like to do something as simple as possible and I didn't see any examples that were for an AngularJS app. The problem is I do not know where to start.

Can someone give me some advice or point me in the right direction.

最满意答案

angular
  .module('test', [])
  .run(function($rootScope) {
    $rootScope.isIpad = /ipad/i.test(navigator.userAgent);
  })
; 
  
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<section ng-app="test">
  <h1>is iPad? <span ng-bind="isIpad | json"></span></h1>
</section> 
  
 


如果您想拥有更强大的解决方案,请查看此处使用jQuery检测iPad用户?

angular
  .module('test', [])
  .run(function($rootScope) {
    $rootScope.isIpad = /ipad/i.test(navigator.userAgent);
  })
; 
  
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<section ng-app="test">
  <h1>is iPad? <span ng-bind="isIpad | json"></span></h1>
</section> 
  
 


if you want to have a more robust solution, have a look here Detect iPad users using jQuery?

更多推荐

本文发布于:2023-08-07 11:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464220.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   浏览器   如何在   rootscope   iPad

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!