Solved

Referrer check to restrict direct file access - javascript

Posted on 2009-04-03
3
493 Views
Last Modified: 2012-06-22
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
Comment
Question by:northlandadv
  • 2
3 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24063028
<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
 

Author Comment

by:northlandadv
ID: 24063047
Hey Thanks!  I'll give it a shot..
0
 

Accepted Solution

by:
northlandadv earned 0 total points
ID: 24119073
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question