900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > window.location.href 加载完成修改title_动态修改document.title失效

window.location.href 加载完成修改title_动态修改document.title失效

时间:2019-02-17 21:26:22

相关推荐

window.location.href 加载完成修改title_动态修改document.title失效

背景:如果页面title是异步获取的数据,那么拿到数据直接使用document.title会在ios低版本出现失效的问题,因为页面加载完成后title被确定,此后不再监听title的change事件

解决方法:获取到数据后,动态创建iframe标签,src指向一个非常小的资源,监听load事件,加载完成立即删除即可更新title

代码:

document.title = this.title;let iframe = document.createElement(iframe);iframe.src = require(/favicon.ico);iframe.style.display = one;let fn = function () {setTimeout(function () {iframe.removeEventListener(load, fn);document.body.removeChild(iframe);console.log( itle, document.title);}, 0);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。