修改页面title
document.title='新的title'
但这样在iOS不生效
解决办法:
// view<div><iframe :src="iframe" style="display: none"></iframe></div>// javascriptdata: {iframe: ''},methods: {setTitle: function (title) {document.title = title// 判断是否为ios设备,ios设备需要通过加载iframe来刷新titleif (navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {this.iframe = '/favicon.ico?' + Math.random()}}}
原生js
// 这里是原有的用iframe解决ios设置标题的兼容性问题 在反复设置标题场景下不生效var iframe = document.createElement('iframe')iframe.src = `/favicon.ico?t=${new Date().getTime()}`iframe.onload = function () {setTimeout(function () {iframe.remove();}, 0)}document.body.appendChild(iframe);