离开和进入页面时改变网页标题,最近也才刚刚开始js学习,下面这段代码简单就是说访客如果离开你的网站之后,站点标题会发生变化。原理是使用了HTML5的Page Visibility API 目前页面可见性API有两个属性,一个事件:
$(document).ready(function(){$(".galleryidpost").lightGallery({selector: ".yoniu-index-img",share: false,share: false,showThumbByDefault: false,autoplayControls: false});});
const dp197 = new DPlayer({ container: document.getElementById("dplayer197"), video: { url: "https://web-static.q6q.cc/files/img/0134911.mp4", }, });
head里面插入代码,自行更换文字即阔
<script>document.addEventListener('visibilitychange',function(){if(document.visibilityState=='hidden'){normal_title=document.title;document.title='别走嘛,我会在原地等你';}else{document.title=normal_title;}});</script>
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有