最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how to call a javascript function on only first page loading only - Stack Overflow

programmeradmin0浏览0评论

I have a javascript function "myFunction()" and i need to call this function on First page load only not for all page.

how can i do it.

I will appreciate a lot your help.

thanks

I have a javascript function "myFunction()" and i need to call this function on First page load only not for all page.

how can i do it.

I will appreciate a lot your help.

thanks

Share Improve this question asked May 24, 2013 at 20:16 Shamim AhmedShamim Ahmed 9312 gold badges16 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

The best is to store in localStorage the fact that you already visited the site (to be precise it's the "origin").

You can put this code in all your pages :

<script>
   if (!localStorage['done']) {
       localStorage['done'] = 'yes';
       myFunction();
   }
</script>

If you want to show the page again for next session, replace localStorage with sessionStorage.

发布评论

评论列表(0)

  1. 暂无评论