below is my code which returns broswer name on button click but I want to display it on page load without button click how can I do this on page load without button click
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
if ((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1) {
alert('Opera');
}
else if (navigator.userAgent.indexOf("Chrome") != -1) {
alert('Chrome');
}
else if (navigator.userAgent.indexOf("Safari") != -1) {
alert('Safari');
}
else if (navigator.userAgent.indexOf("Firefox") != -1) {
alert('Firefox');
}
else if ((navigator.userAgent.indexOf("MSIE") != -1) || (!!document.documentMode == true)) //IF IE > 10
{
alert('IE');
}
else {
alert('unknown');
}
}
</script>