Display alert only once
You can use localStorage (not compatible with older browsers):
<script type="text/javascript">
var alerted = localStorage.getItem('alerted') || '';
if (alerted != 'yes') {
alert("My alert.");
localStorage.setItem('alerted','yes');
}
</script>
Or you can use cookies, give a look to this answer for a full example code: https://stackoverflow.com/a/21567127/3625883
Set a cookie when you show the alert. Then, if the cookie is set, you will know not to show the alert again. If it is not set, you know that you haven't shown the alert yet and should do so now.
You can read about setting cookies in JavaScript here.