document.title在某些app中无法更改的解决方案

function setDocumentTitle(str){
    setTimeout(()=> {
        //利用iframe的onload事件刷新页面
      let title = document.getElementsByTagName('title')[0];
      title.innerText = str;
      let iframe = document.createElement('iframe');
      iframe.style.visibility = 'hidden';
      iframe.style.width = '1px';
      iframe.style.height = '1px';
      iframe.onload = function () {
          setTimeout(function () {
            document.body.removeChild(iframe);
          }, 0);
       };
        document.body.appendChild(iframe);
      }, 0);
}

 

你可能感兴趣的:(web前端)