JavaScript How can I create a “first-load” event in html or Javascript?

I'm starter. I have an idea. I want to implement an event like this. Is it possible?

<html>
<head>
<title>First visit event</title>

<script>
function do_something()
{
    alert("Hello my friend. This is your first visit.");
}
</script>

</head>

<body firstVisitEvent="do_something()">
</body>
Answer:1

Localstorage is probably the way to go. Here is a bit of info on it: http://diveintohtml5.info/storage.html

Basically it allows you to store small amounts of data on the user's machine (up to 5mb in most browsers). So all you need to do is set a flag in there letting you know that the user has already visited, and if that flag isn't present on page load, show the message.

// Run function on load, could also run on dom ready
window.onload = function() {
    // Check if localStorage is available (IE8+) and make sure that the visited flag is not already set.
    if(typeof window.localStorage !== "undefined" && !localStorage.getItem('visited')) {
         // Set visited flag in local storage
         localStorage.setItem('visited', true);
         // Alert the user
         alert("Hello my friend. This is your first visit.");   
    }
}

This should work in all browsers where local storage is available. See caniuse.com for reference. http://caniuse.com/#search=localstorage

Answer:2

You have a couple of options: storing a cookie on the client or utilizing the local storage of html5. Either of these could be checked on page load.

Here is a link for getting started with HTML5 web storage:

http://www.w3schools.com/html/html5_webstorage.asp

Answer:3

you can do it for chrome in following way

<html>
<head> 
<title>First visit event</title>    
<script> 
function do_something() {
    if(typeof(localStorage.setVisit)=='undefind' || localStorage.setVisit==''){
        localStorage.setVisit='yes';
        alert("Hello my friend. This is your first visit.");
    }
} 
</script>

</head>

<body onload="do_something()"> </body>
Answer:4

Facebook React can use a unidirectional data flow pattern called Flux to give structure to applications by using Views, Actions, Stores and a Dispatcher. I have found the following Flux libraries for ...

Facebook React can use a unidirectional data flow pattern called Flux to give structure to applications by using Views, Actions, Stores and a Dispatcher. I have found the following Flux libraries for ...

Alright, so I was wondering if there was an alternative, lightweight way to creating an image map. Basically, I want to take this image: And have the sections of the diagram light up when they are ...

Alright, so I was wondering if there was an alternative, lightweight way to creating an image map. Basically, I want to take this image: And have the sections of the diagram light up when they are ...

I have a web application that uses requirejs to load its modules. The web applications works without problems in any desktop browser, it also works on iOS and Android when packaged with Cordova. Does ...

I have a web application that uses requirejs to load its modules. The web applications works without problems in any desktop browser, it also works on iOS and Android when packaged with Cordova. Does ...

I'm trying to get the coordinates of the Circle drawing in ol 3.5. I use the evt.coordinate function to get the coordinates, but I keep getting undefined. Here's a piece of my code: this....

I'm trying to get the coordinates of the Circle drawing in ol 3.5. I use the evt.coordinate function to get the coordinates, but I keep getting undefined. Here's a piece of my code: this....