微信title修改hack
微信的title只会在进入页面时读取一次,并不会触发title的change事件。
(因为刷新页面时能及时显示title,这个代码就是用iframe做了一次伪请求,在body中添加一个iframe标签,请求成功之后再移除dom)123456789101112131415161718192021function changeTitle(title) { document.title = title let body = document.body let iframe = document.createElement('iframe') iframe.src = '../../img/wh.png' iframe.style.display = 'none' body.appendChild(iframe) if (iframe.attachEvent) { body.attachEvent('onload', function() { setTimeout(function() { body.removeChild(iframe) }, 0) }) } else { iframe.onload = function() { setTimeout(function() { body.removeChild(iframe) }, 0) } }}
已知bug:
在使用该方法后,有时会在页面下面出现白条,(虽然iframe已经加了display: none;并且已经删除),解决方法是在css中直接123body iframe { display: none;}