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=新标题就好了 这样 ...
随机推荐
- Centos yum国内源及配置含义
Centos yum源的位置: /etc/yum.repos.d,可以通过配置文件/etc/yum.conf指定其他位置 主要的yum源种类:前两个是必须的,不然yum安装很多软件时会失败.yum本来 ...
- 创建MySQL用户 赋予某指定库表的权限
摘自: http://renxiangzyq.iteye.com/blog/763837 update ERROR 1364 (HY000): Field 'ssl_cipher' doesn't h ...
- AndroidStudio中Handler类的内存溢出风险
package com.test.king.xmlparser; import android.annotation.SuppressLint; import android.app.Activity ...
- 发现一个“佛系记账本”
因为这是一款微信小程序,张小龙大力推崇的"用完即走"完美地适合记账应用. 不用下载.不用安装.不用注册.不用各种授权,只要从微信进入,就能记账,账本只与微信关联. 换手机.换PAD ...
- phpt5支付宝登陆支付接口解析
先看效果图 下面的源码来源网络,自己对照修改. 放入一个插件库中,方便管理 创建支付类 1.发起支付 public function init() { $order_id = $_REQUEST['o ...
- Delphi10.2 DPR文件
通过选择[Project | View Source],可以看到DPR文件的基本面貌,操作如下: 默认的 Delphi 项目文件的内容如下: program Project1; {关键字 progra ...
- Effective Java 第三版——70. 对可恢复条件使用检查异常,对编程错误使用运行时异常
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- PHP-问题处理Fatal error: Uncaught Error: Call to undefined function simplexml_load_file()
1.问题 今天重新安装了ubuntu,PHP,MySQL,Apache,到测试CMS项目时发生一个错误: Fatal error: Uncaught Error: Call to undefined ...
- 使用protobuf编译onnx.proto过程中的一些问题总结
使用git clone下载protobuf的源代码,然后git checkout到branch2.7.0: 编译protobuf,先在代码顶层目录执行./configure,然后执行make,成功后执 ...
- 关于XCode工程中PrefixHead.pch文件的使用
1.首先先清除pch文件在工程中的作用: 存放一些全局的宏(整个项目中都用得上的宏) 用来包含一些全部的头文件(整个项目中都用得上的头文件) 能自动打开或者关闭日志输出功能 2.由于新建的XCode工 ...