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);
}
本文介绍了一种使用JavaScript修改网页标题并在修改后通过隐藏的iframe触发页面刷新的方法,适用于需要动态更新页面标题的场景。
371

被折叠的 条评论
为什么被折叠?



