Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

JavaScript to print browser name and version

// JavaScript to print browser name
// JavaScript to print browser version

Description

This script is used to print the browser name and version. The statement var browser=navigator.appName; fetches the browser name and stores it in the variable browser and bversion=navigator.appVersion; fetches the browser version and stores it in the variable bversion.

Code


<html>

<head>

<title>Name of Browser</title>

<script>

var browser=navigator.appName;

var bversion=navigator.appVersion;

var version=parseFloat(bversion);

document.write("<Font color=RED>Browser Name: </font>"+browser);

document.write("<br>");

document.write("<Font color=RED>Browser Version: </font>"+bversion);

</script>

<body></body>

</head>

</html>


Output

javascript to print browser name and version
Java Script - Browser name and version

JavaScript to display running time in the browser


Description


This script displays the running time in Hours, Minutes and Seconds format. The Date() function is used to fetch the current system date. getHours(), getMinutes and getSeconds() function is used to fetch hours, minutes and seconds respectively from the value of Date() function.

Code

<html>

<head>

<title>Display running time using JavaScript</title>

<script>

function starttime()

{

var today=new Date();

var hours=today.getHours();

var minutes=today.getMinutes();

var seconds=today.getSeconds();

var i;

var x;

x=checkampm(hours);

m=checktime(minutes);

s=checktime(seconds);

document.getElementById('txt').innerHTML=
"<font color=BLACK><h1>"+hours+":"+minutes+":"+seconds+" "+x+"</h1>";

t=setTimeout('starttime()',100);

}

function checktime(i)

{

if(i<10)

i="0"+i;

return(i);

}

function checkampm(i)

{

if(i<12)

return('AM');

else

return('PM');

}

</script>

</head>

<body onload=starttime();>

<span id='txt' style="background_color=WHITE">Time is</span>

</body>

</html>


Output


Display current time in the browser using JavaScript
Display time using JavaScript