Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 javascript 函数“myFunction()”,我需要在首页加载时调用此函数,而不是所有页面。
我该怎么做。
我将非常感谢您的帮助。
谢谢
最好的办法是存储localStorage您已经访问过该站点的事实(准确地说,它是“来源”)。
localStorage
您可以将此代码放在所有页面中:
<script> if (!localStorage['done']) { localStorage['done'] = 'yes'; myFunction(); } </script>
如果您想在下一次会话中再次显示该页面,请替换localStorage为sessionStorage.
sessionStorage