I want to check if the subdomain demo
exists in my URL.
So if my URL is either https://demo.stackoverflow.com/
or https://demo.stacks.com/
or https://demo.hello.com/
, the function should return true.
If the URL is just https://stackoverflow.com/
, without the word demo
, the function should return false.
So how can I do that?
Current Code
<script>
if (window.location.hostname === 'https://demo.stackoverflow.com/') {
document.write('<script src="./script.min.js"></' + 'script>');
}
</script>