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

I have a javascriptfunction "myFunction()" and i need to call this function on First page l

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745132881a4613057.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信