First Load [Call function]

is there any function that can tell if the page is being loaded for the first time? I need to call a function only when the page is initially loaded.

You could use localStorage to determine whether a user has visited or not but it only works in modern browsers and IE8+, for a fallback if you need to support IE7 and below cookies would be the next option.

ok i don’t need the function to call the first time they ever visited the site, but each time they visit the site. something like a

window.onload

If you place your JavaScript at the bottom of the page where it belongs then it can run straight away without needing window.onload

ok understood but how would I know if the function is being called for the first time. Ok the senario is that the first function my page loads is function1. However the first time function1 is called it needs to do something like replaceState. However the next time I call function1 while on this site it checks to see if it was called before if not then no replaceState. I hope this better explains what I am trying to do.

function1 = function() {
   // code to run only the first time function1 is called goes here
   function1 = function() {
      // code to run every time function1 is called goes here
   }
   function1(); // leave out this line if the code to run every time should not run the first time
}

Ok never saw this before will give it a go.