react 动态修改 document.title
装饰器
// withComponents/withHeaderBar.js
import React, { Component } from "react";
import HeaderBar from "../components/headerAppBar";
const l = console.log;
const styles = {
root: {
marginTop: "3rem",
},
};
export default function withHeaderBar({
title,
children,
position,
component = true,
}) {
return function(Target) {
return class WithHeaderBar extends Component {
componentWillMount() {
// document.title = title;
setTitle(title);
}
render() {
const style = position === "fixed" ? styles.root : {};
return component ? (
<div style={{ ...style }}>
<HeaderBar title={title} children={children} position={position} />
<Target {...this.props} />
</div>
) : (
<Target {...this.props} />
);
}
};
};
}
function setTitle(t) {
document.title = t;
var iframe = document.createElement("iframe");
iframe.style.visibility = "hidden";
iframe.setAttribute("src", "favicon.ico");
var iframeCallback = function() {
setTimeout(function() {
iframe.removeEventListener("load", iframeCallback);
document.body.removeChild(iframe);
}, 0);
};
iframe.addEventListener("load", iframeCallback);
document.body.appendChild(iframe);
}
使用
@withHeaderBar({
title: "附近优惠",
position: "fixed",
})
class NearbyOffers extends Component {
render() { ... }
}
react 动态修改 document.title的更多相关文章
- hack在微信等webview中无法修改document.title的情况
var $body = $('body'); document.title = '确认车牌'; // hack在微信等webview中无法修改document.title的情况 var $iframe ...
- 微信等webview中无法修改document.title的情况
// hack在微信等webview中无法修改document.title的情况 var $iframe = $('<iframe src="https://www.bbtree.co ...
- 基于Vue的SPA动态修改页面title的方法
最近基于VUE做个SPA手机端web发现动态修改页面标题通过document.title=xxxx 来修改着实蛋疼,而且在IOS的微信端据说没效果.百度发现要针对IOS的微信做点额外的操作,即:创建一 ...
- js动态修改浏览器title
script标签依据浏览框的失焦获焦进行函数操作(操作简单放到HTML文件下的head标签下就可以) <script> window.onfocus = function () { doc ...
- ng 设置动态的document title
使用Title服务 相关文章 配置路由, 添加data.title参数 import { NgModule } from '@angular/core'; import { RouterModule, ...
- easyui 动态修改窗口title
http://blog.csdn.net/liu251890347/article/details/39292307?utm_source=tuicool 使用easyui作为前台框架极大的节省了项目 ...
- 用document.title=“xxx”动态修改title,在ios的微信下面不生效的解决办法!
//需要jQuery var $body = $('body'); document.title = 'title'; // hack在微信等webview中无法修改document.title的情况 ...
- 用document.title=“xxx”动态修改title,在ios的微信下面不生效
单页应用里整个页面只会在第一次完全刷新,后面只会局部刷新(一般不包括head及里面的title),所以无法在服务器端控制title,只能在页面刷新的时候通过js修改title.常规做法如下,可惜在iO ...
- JS动态修改微信浏览器中的title
JS动态修改微信浏览器中的title我们的原理是设置一个ifame然后我们再加载一下就可以实现了,具体的例子如下所示. 平时使用JS修改title,直接document.title=新标题就好了 这样 ...
随机推荐
- Docker技术快速精通指南
doctor专业网站:http://www.dockerinfo.net/ Docker中文文档 csdn 的docker专栏: Docker技术快速精通指南
- Delphi 获取当前鼠标下的控件内容
Delphi 获取当前鼠标下的控件内容 主要函数: GetCursorPos://获取鼠标的位置 WindowFromPoint://获取制定point下的handle GetClassName:// ...
- [Python设计模式] 第21章 计划生育——单例模式
github地址:https://github.com/cheesezh/python_design_patterns 单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式 ...
- grid - 网格项目对齐方式(Box Alignment)
CSS的Box Alignment Module补充了网格项目沿着网格行或列轴对齐方式. <view class="grid"> <view class='ite ...
- javascript umd esm slim
在CDN的连接中看到多个连接时如何选择? JavaScript 模块现状 UMD和ECMAScript模块 https://cdn.bootcss.com/popper.js/1.13.0/esm/p ...
- 小程序学习笔记三:页面文件详解之视图层WXML、WXS、WXSS文件
视图层:Pages主要有 wxml页面文件和模板文件.wxs脚本文件.wxss样式文件:component是抽取出来的业务单元,同样拥有wxml页面文件和模板文件.wxs脚本文件.wxss样式文件 ...
- POSIX 线程清理函数
POSIX 多线程的 cleanup 函数 控制清理函数的函数有两个,一个是 pthread_cleanup_push(), 用来把清理函数压入栈中,另一个是 pthread_cleanup_pop( ...
- SQL Server 性能优化实战系列(二)
SQL Server datetime数据类型设计.优化误区 一.场景 在SQL Server 2005中,有一个表TestDatetime,其中Dates这个字段的数据类型是datetime,如果你 ...
- exp导出数据时丢表
友军发来消息,说使用exp导出某个schema的数据的时候,发现有些表没有导出来.因为一直没有使用exp的习惯,就使用exp\expdp再次导出一次,分析二者的日志,发现exp的确有些表没有导出. 问 ...
- maven project 报错解决方法
1 maven 在添加包后出错,project 处有红线的解决办法 Maven默认会使用本地缓存的库来编译工程,对于上次下载失败的库,maven会在~/.m2/repository/<group ...