/    Sign up×
Community /Pin to ProfileBookmark

Javascript code fine on FF but broken on IE?

Hello, I wonder if anyone can help me?

I have a page on my site which I want people to be able to access only by clicking on a link from another page within my site – i.e I do not want them to be able to go their directly.

After trawling various sites I managed to make my own code.

<SCRIPT LANGUAGE=”JavaScript”>

var requiredfrom = “http://www.mywebsite.com/auth.htm“;
var redirect =”http://www.mywebsite.com/error.html“;
if (document.referrer.indexOf(requiredfrom) == -1) {
alert(“Access Denied”);
window.location=redirect;
}

</script>

To my suprise it actually worked – hwoever upond testing it out in IE it just redirects to the error page.

Any tips? I must point out I am a design rather than a coder – hence the probably stupid attempt at doing it myself!

Thanks

JP

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Jan 18.2007 — Have you looked at what IE says the document.referer actually is? You probably will need to use toLowerCase() if the referer is not blocked.

ALso if you want to be secure, you need to learn about serverside languages. All I have to do is noscript or disbale JavaScript and I will not be redirected.

Eric
Copy linkTweet thisAlerts:
@klanga2049authorJan 18.2007 — Hi, I tested it with this code

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">

<!-- Hide script from old browsers

if (document.referrer != '')

document.write('Thanks for visiting from ' + document.referrer);

//-- Stop hiding script -->

</SCRIPT>

If i use FF it writes the url i came from, if i use IE it doesn't!
Copy linkTweet thisAlerts:
@klanga2049authorJan 18.2007 — I have done a little more reading and apprently in IE it can sometimes not reffer a URL.

Is there any other way to check where a user has come from then make a code like this:
---------------------------


If user has come from x then do nothing

else

if user has come from y - pop up an alert box saying "access denied"
---------------------------



It';s the passing of some variable from page x that is the problem - then checking that variable.

That is pretty much all I need!
Copy linkTweet thisAlerts:
@A1ien51Jan 18.2007 — Why don't you just use a session cookie.

Eric
Copy linkTweet thisAlerts:
@klanga2049authorJan 18.2007 — becasue I am stupid - I will google session cookie and try that ?

cheers
Copy linkTweet thisAlerts:
@kia2Feb 04.2007 — that's a beautiful script you made...it is EXACTLY what i needed but i also need to make it work in IE. Had done some researching on the net that the document.referrer does not work in IE and would return empty

Some suggest to use window.history.back()

or

var Sent;

Sent = document.referrer;

if (Sent.length > 0) {

window.history.back(); }

Others suggest to make the protected url session time-out instead.

As I am not a coder (a designer as well), i don't understand how to apply window.history.back() to make the above script work within klang2049's script:

<SCRIPT LANGUAGE="JavaScript">

var requiredfrom = "http://www.mywebsite.com/auth.htm";

var redirect ="http://www.mywebsite.com/error.html";

if (document.referrer.indexOf(requiredfrom) == -1) {

alert("Access Denied");

window.location=redirect;

}

</script> [/QUOTE]


Any one could help??
Copy linkTweet thisAlerts:
@felgallFeb 04.2007 — Anyone can turn off the referrer field in their browser or firewall or set it ti what they like. It is a user controlled field.
Copy linkTweet thisAlerts:
@kia2Feb 04.2007 — Anyone can turn off the referrer field in their browser or firewall or set it ti what they like. It is a user controlled field.[/QUOTE]

thanks. may i know what is the most simple method to achieve the same result?
×

Success!

Help @klanga2049 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...