Angularjs 动态改变title标题(兼容ios)
tanmuxue 人气:0废话不多说了,直接给大家贴代码了,具体代码如下所示:
<pre name="code" class="javascript">angular.module('myApp.loginCtrl', []) .config(function($httpProvider) { $httpProvider.defaults.headers.post['Content-Type']='application/x-www-form-urlencoded;charset=utf-8'; //改变header中content-type的格式 }) .controller('loginCtrl',['$scope','$http',function($scope,$http){}]) //兼容ios动态改变title标题 .run(['$location','$rootScope',function($location, $rootScope){ $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) { $rootScope.title = toState.title }); $rootScope.$watch('title',function(title){ var body = document.getElementsByTagName('body')[0]; document.title = title; var iframe = document.createElement("iframe"); iframe.title = '登陆'; iframe.width = 0; iframe.height = 0; iframe.src = '//m.baidu.com/favicon.ico'; iframe.style.display = 'none'; iframe.addEventListener('load', function() { setTimeout(function() { // iframe.removeEventListener('load'); document.body.removeChild(iframe); }, 0); }); document.body.appendChild(iframe); }); }]); </pre><br> <br> <pre></pre> <pre code_snippet_id="2083087" snippet_file_name="blog_20161229_4_8475823" name="code" class="javascript">//路由<pre name="code" class="javascript"> .state('deliciousFood',{ title:'美食住宿', url:'https://img.qb5200.com/download-x/deliciousFood', templateUrl:'/hq/viewshttps://img.qb5200.com/download-x/deliciousFoodhttps://img.qb5200.com/download-x/deliciousFood.html', controller:'deliciousFoodCtrl', resolve:{ loadMyCtrl:['$ocLazyLoad',function($ocLazyLoad){ return $ocLazyLoad.load([ '/hq/viewshttps://img.qb5200.com/download-x/deliciousFoodhttps://img.qb5200.com/download-x/deliciousFoodCtrl.js', ]).then(function(){}) }] } })</pre><br> <pre></pre> <br> </pre>
以上所述是小编给大家介绍的Angularjs 动态改变title标题(兼容ios),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
加载全部内容