用document.title=“xxx”动态修改title,在ios的微信下面不生效
单页应用里整个页面只会在第一次完全刷新,后面只会局部刷新(一般不包括head及里面的title),所以无法在服务器端控制title,只能在页面刷新的时候通过js修改title。常规做法如下,可惜在iOS微信浏览器无效。
问题原因:
因为微信浏览器首次加载页面初始化title后,就再也不监听 document.title的change事件。
解决方案:
修改title之后,给页面加上一个内容为空的iframe,随后立即删除这个iframe,这时候会刷新title。但是如果简单的这样设置,一般是会有闪动的,所以可以设置
方法一:
完整代码:
- document.title = '设置标题HTTP';
- const iframe = document.createElement('iframe');
- iframe.style.cssText = 'display: none; width: 0; height: 0;';
- iframe.src = 'http://desk.fd.zol-img.com.cn/t_s960x600c5/g5/M00/05/0F/ChMkJ1erCriIJ_opAAY8rSwt72wAAUU6gMmHKwABjzF444.jpg';
- //iframe.src = require('./img/text_delete.png');
- const listener = () => {
- setTimeout(() => {
- iframe.removeEventListener('load', listener);
- setTimeout(() => {
- document.body.removeChild(iframe);
- }, 0);
- }, 0);
- };
- iframe.addEventListener('load', listener);
- document.body.appendChild(iframe);
方法二:
封装了一个只在IOS的状态下处理的方法:
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);
}
}
用document.title=“xxx”动态修改title,在ios的微信下面不生效的更多相关文章
- 用document.title=“xxx”动态修改title,在ios的微信下面不生效的解决办法!
//需要jQuery var $body = $('body'); document.title = 'title'; // hack在微信等webview中无法修改document.title的情况 ...
- 聊聊 Vue 中 title 的动态修改
由于之前的 Vue 项目打包成果物一直是嵌入集成平台中,所以一直没有关注过项目的 title.直到最近,突然有个需求,要求点击按钮在集成平台外新开一个页面,此时我才发现,原来我的项目的 title 一 ...
- vue单页面应用中动态修改title
https://www.jianshu.com/p/b980725b62e8 https://www.npmjs.com/package/vue-wechat-title 详细信息查看:vue-wea ...
- vue-wechat-title动态修改title
在使用Vue制作项目的过程中,发现title没有变化 所以使用vue-wechat-title插件动态修改tilte 一.安装 npm vue-wechat-title --save 二.引入和使用 ...
- 微信小程序动态修改title,动态配置title,动态配置头部,微信小程序动态配置头部
微信小程序的title是在json里面配置的 "navigationBarTitleText": "title名称" 这种title是固定死的不灵活处理一些页面 ...
- js动态修改title
问题描述: 由于微信浏览器只在页面首次加载时初始化了标题title,之后就没有再监听 window.title的change事件.所以这里修改了title后,立即创建一个请求,加载一个空的iframe ...
- 在vue中如何动态修改title标签的值
建议用vue-wechat-title插件为微信动态设置标题 1,首先安装插件 cnpm install vue-wechat-title --save 2,在main.js中引入 Vue.use(r ...
- vue动态修改title
1.项目中,cmd下 ,运行:cnpm install vue-wechat-title --save 2.在 main.js 中,设置: import VueWechatTitle from 'vu ...
- Vue动态修改网页标题
业务需求,进入页面的时候,网页有个默认标题,加载的网页内容不同时,标题需要变更. 例:功能授权,功能授权(张三). Vue下有很多的方式去修改网页标题,这里总结下解决此问题的几种方案: 一.最笨方案 ...
随机推荐
- Delphi XE10让android的界面设计摆脱繁杂
设计一个选项卡. 大体图样: 1.创建一个multi_Device_Application;2.在form上放一个Rectangle1,设置align为top.设置fill属性的kind为Gradie ...
- C#解压、压缩RAR文件
using System; using System.Collections.Generic; using System.Text; using System.IO; using Microsoft. ...
- 解决win8找不到没有AppData文件夹
现象:今天打开win8,由于是从xp直接过渡到win8,所以想寻找类似于AppData的文件夹.但是在user/用户名/下面木有. 解决:这是个隐藏文件,和xp一样,取消隐藏文件夹即可看到. 然后就可 ...
- BT5之网络配置
输入ifconfig命令,可以查看当前IP地址设置情况.查看路由表的命令(用来检查默认网关是否设置正确):netstat -r 一.让BT5自动获取IP地址 自动获取IP地址,使用dhclient命令 ...
- 增加Android可用内存
In the development of TV applications, especially when dealing with images were more likely to feel ...
- redis消息队列
http://blog.csdn.net/21aspnet/article/details/7455032
- html5 高级动画精灵
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- access to modified closure 闭包的问题
; i < listBoxDevices.Items.Count; i++) { var tempDeviceId = listBoxDevices.Items[i].ToString(); i ...
- [HDU 1963] Investment
Investment Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descrip ...
- POJ2236 Wireless Network 并查集
水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...