I am trying to display the nslookup value from the javascript function, that return the nslookup value back to the html while loading the page.
i have following script in the html page:
<html>
<style type="text/css">
.Table
{
display: table;
}
.Title
{
display: table-caption;
text-align: center;
font-weight: bold;
font-size: larger;
}
.Heading
{
display: table-row;
font-weight: bold;
text-align: center;
}
.Row
{
display: table-row;
}
.Cell
{
display: table-cell;
border: solid;
border-width: thin;
padding-left: 20px;
padding-right: 20px;
}
</style>
<body onload="myFunction()">
<h1>"The dns ip is: " <span id="myID"></span></h1>
<div class="Heading">
<div Class="Cell">
<p>G</p>
</div>
<div Class="Cell">
<p>facebook.com</p>
</div>
<div id="test">
<span id="h" class="Cell">
<p>H</p>
</span>
<span id="e" class="cell">
<p>E</p>
</span>
<span id ="Time" class="Cell">
<P> </P>
</span>
</div>
<div Class="Cell">
<p></p>
</div>
</div>
</body>
<button type="button" onclick="myFunction()">Refresh</button>
<script>
function myFunction()
{
//document.body.style.backgroundColor = "red";
document.getElementById("h").style.background="green";
const dns = require('dns');
var status="";
dns.lookup('facebook.com', function(err, result){
var status = result;
});
document.getElementById("Time").innerHTML=status;
}
</script>
</html>
Expected: I expect to get the dns value for the url facebook.com to be returned and displays in "The dns ip is:" field
Actual: Nothing is returning from the script to display over there
Appreciate if anyone can help on this?