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