newcool
newcool

Reputation: 319

Is it possible to allow html to only run on a specific domain?

What I am trying to do is, if my html/css/javascript is loaded on another domain the page will clear itself, so the page will look blank when it is fully loaded. It's like a fingerprint just for my domain.

As if right now there isn't much documentation regarding this. I have found a few examples but they are not implementable.

I've seen it done before, if it didn't match with the domain name then the page would be blank.

Does anyone know how I can do this?

Upvotes: 0

Views: 981

Answers (2)

Harish
Harish

Reputation: 1911

you can add this in your files

<style>
      html {
        display: none;
      }
    </style>
    <script>

      if ( top.location.host === "www.xyz.com" /* your domain */) {
        document.documentElement.style.display = "block";
      }
    </script>

Upvotes: 1

FZs
FZs

Reputation: 18609

You can get the domain name in JS by window.location.host, and you can clear the page using window.location.replace('about:blank'); but this method can be bypassed/removed from code.

if(window.location.host !== 'your.domain.com') window.location.replace('about:blank')

Upvotes: 1

Related Questions