Check if the domain your script is running on belongs to a local machine
first load script into your file ...
<script src="local-domain-checker.js"></script>
... and than call the function
// without an argument
window.isLocal(); // returns either true or false
// with an argument
window.isLocal("localhost"); // true
window.isLocal("127.0.0.1"); // true
window.isLocal("::1"); // true
window.isLocal("foobar.local"); // true
window.isLocal("foobar.localhost"); // true
window.isLocal("foobar.test"); // true
window.isLocal("example.org"); // false
window.isLocal("142.42.42.42"); // false