通常情况下,我们使用document.title=”标题名”来动态的修改标题,但是此方法在微信iOS端并没有用,查了不少资料,终于解决这个问题啦。现在把代码分享出来给大家
function wxSetTitle(title) {
document.title = title;
var mobile = navigator.userAgent.toLowerCase();
if (/iphone|ipad|ipod/.test(mobile)) {
var iframe = document.createElement('iframe');
iframe.style.visibility = 'hidden';
iframe.setAttribute('src', 'loading.png');
var iframeCallback = function() {
setTimeout(function() {
iframe.removeEventListener('load', iframeCallback);
document.body.removeChild(iframe);
}, 0);
};
iframe.addEventListener('load', iframeCallback);
document.body.appendChild(iframe);
}
}
直接调用此方法就可以啦

本文介绍了一种在微信iOS环境中动态更改网页标题的方法,并提供了一个JavaScript函数实现。通过创建隐藏的iframe元素触发页面标题更新,解决了document.title在微信内无法生效的问题。
3906

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



