HTML 正文加载函数需要删除并使用 cookie 执行相同的函数,但只能进行第一次访问

html body onload function need to remove and execute the same function with cookie but only first visit

本文关键字:函数 访问 第一次 执行 加载 正文 删除 cookie HTML      更新时间:2023-09-26

这是我的HTML页面内容(其中的一部分(

<body onLoad="javascript:introJs().start();"> <div id="page"> <div id="header"> <a href="javascript:void(0);" onclick="javascript:introJs().start();" class="friends left">Link</a> Headline </div>

我已经在我的 html 页面上实现了介绍,如上所示。 但我需要自动执行在html onLoad上给出的功能。 但仅在第一次访问cookie时。我对饼干一无所知。任何人都可以更改或创建一个cookie,以便在首次访问时自动执行介绍。

你可以使用本地存储,比如,

脚本

window.onload=function(){
   if(!localstorage.getItem('intorjsInit') && localstorage.getItem('intorjsInit')!=1)
   {
      javascript:introJs().start();
   }
   else
   {
      localstorage.setItem('intorjsInit',1);
   }
};

.HTML

<body><div id="page">.....