• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

Referrer check to restrict direct file access - javascript

I need a simple javascript I can put in the top of my HTML page to check the referrer, and show/hide the page.  I know this isn't the most secure resolution, but I only need it as a temp solution.

For example, I only want to allow access from two domains (domain1.com and domain2.com).  

Site users will be coming from inside an application to this static HTML page, so the referrer will be correct and will allow it to be viewed.  I want to DISSALLOW access by direct URL, which would lack the correct referrer.

I can't post any page code due to NDA  :(

Thanks for your help!
0
northlandadv
Asked:
northlandadv
  • 2
1 Solution
 
Michel PlungjanIT ExpertCommented:
<script>
if (document.referrer.indexOf('domain1') == -1 and document.referrer.indexOf('domain2') == -1) {
  document.write('<style>* { display:none }</style>')
}
</script>

or

<script>
if (document.referrer.indexOf('domain1') == -1 and document.referrer.indexOf('domain2') == -1) {
   location.replace('goaway.html')
 }
 </script>
 
0
 
northlandadvAuthor Commented:
Hey Thanks!  I'll give it a shot..
0
 
northlandadvAuthor Commented:
I was never able to get this to work  :(   I ended up just using the htacess in the end, since it was less hassle.  Thanks anyway.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now