hugo 博客 监听浏览器title 动态改变浏览器title标题

找到head.html

themes/maupassant/layouts/partials/head.html

添加监听js

可以从html中发现,分为home页面和其他页面,两种展示的不同,所以需要改这两部分

  {{ if .IsHome -}}
<title>{{ .Site.Title }} | {{ .Site.Params.subtitle}}</title>
<meta property="og:title" content="{{ .Site.Title }} | {{ .Site.Params.subtitle}}">
<meta property="og:type" content="website">
<meta name="Keywords" content="{{.Site.Params.keywords}}">
<meta name="description" content="{{ .Site.Params.description }}"> <!--添加部分-start--> <script>
document.addEventListener('visibilitychange',function(){
if( document.visibilityState == 'hidden' ){
normal_title = document.title;
document.title = 'ヽ(●-`Д´-)ノ你丑你就走!';
}else{
document.title = 'ヾ(Ő∀Ő3)ノ你帅就回来!';
setTimeout(function(){
document.title = normal_title;
}, 1200)
}
});
</script>
<!--添加部分-end--> {{- else -}}
<title>{{ .Title }} | {{ .Site.Title }}</title> <!--添加部分-start-->
<script>
document.addEventListener('visibilitychange',function(){
if( document.visibilityState == 'hidden' ){
normal_title = document.title;
document.title = 'ヽ(●-`Д´-)ノ你丑你就走!';
}else{
document.title = 'ヾ(Ő∀Ő3)ノ你帅就回来!';
setTimeout(function(){
document.title = normal_title;
}, 1200)
}
});
</script>
<!--添加部分-end-->

最新文章

  1. OpenGL中glVertex、显示列表(glCallList)、顶点数组(Vertex array)、VBO及VAO区别
  2. 第一次打开Photoshop时的基本设置
  3. 20155306白皎 学习技能+C语言学习
  4. compile error
  5. Block的使用及循环引用的解决
  6. 云计算之路-阿里云上:2014年6月12日12点IIS请求到达量突降
  7. html成绩单表格
  8. MVVM with ReactiveCocoa
  9. CSS引入方式的区别详解
  10. myeclipse10安装egit和使用
  11. 通知实战 设置通知图片(iOS10以后的)
  12. React 中的key值
  13. Linux CentOS设置定时重启:crontab
  14. 基于STM8的UART发送和中断接收---STM8-第二章
  15. 洛谷 P1392 取数
  16. NOIP2018TG题解
  17. bootstrapTable--4.删除和批量删除
  18. Tomcat------如何更改被IIS占用的80端口
  19. UVALive - 2927 &quot;Shortest&quot; pair of paths(最小费用最大流)题解
  20. Javascript屏蔽鼠标右键-超简单,不过还是记录一下

热门文章

  1. python中函数与方法的区别
  2. codefoces D. Phoenix and Science
  3. JVM之对象创建、对象内存布局、对象访问定位
  4. 尝试做一个.NET简单、高效、避免OOM的Excel工具
  5. Linux和Docker的Capabilities介绍及Setcap命令
  6. JAVA线上故障排查手册-(推荐)
  7. SpringBoot-13 Dubbo实战
  8. c 结构体内存对齐详解
  9. malloc 函数分析 glibc2.23
  10. JRebel激活