佚名通过本文主要向大家介绍了title标签,html title标签,网页title标签,title标签优化,图片alt title标签等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: 怎么修改ios上微信浏览器title标签
描述:
解决方案1:
描述:
问题1:我现在找到的解决办法是
xxx.setDocumentTitle = function(title) {
document.title = title;
if (/ip(hone|od|ad)/i.test(navigator.userAgent)) {
var i = document.createElement('iframe');
i.src = '/favicon.ico';
i.style.display = 'none';
i.onload = function() {
setTimeout(function(){
i.remove();
}, 9)
}
document.body.appendChild(i);
}
}
这种方法我看不懂,求解释
问题2:为什么会出现这种情况?安卓端的微信浏览器可以用dom修改title,同样代码在ios端为啥没效果?
解决方案1:
webview中包括微信的浏览器IOS设备是无法通过document.title来更改标题的
给你分享一段代码吧
核心思想是内嵌一个iframe去发起一个请求来触发IOS设备中更新title
changeTitle: function (title) {
var isIOS = /iPad|iPhone|iPod/i.test(navigator.userAgent);
if(isIOS){
var $body = $('body');
document.title = title;
// 这儿的src可以换成你的一个地址,尽量开销小,响应速度快
var $iframe = $('<iframe src="http://client.map.baidu.com/shoppingmall/images/transparent.gif"></iframe>');
$iframe.on('load',function() {
setTimeout(function() {
$iframe.off('load').remove();
}, 0);
}).appendTo($body);
} else {
document.title = title;
}
}
解决方案2:
直接change函数中 document.title = "xxx"
赋值,
你找的代码/ip(hone|od|ad)/i.test(navigator.userAgent)
判断是ios设备(正则判断navigator.userAgent)
至于为什么
创建一个iframe, 去改, 坐等神评.