EN
JavaScript - check if script is run on localhost in web browser
4 points
In this article, we would like to show you how to check if the script is run on localhost in a web browser using JavaScript.
Quick solution:
xxxxxxxxxx
1
if (location.hostname === 'localhost' || location.hostname === '127.0.0.1') {
2
console.log('This is a localhost.');
3
}
In this section, we present a practical example of the above solution executed under localhost.
