Link to home
Start Free TrialLog in
Avatar of shanth_77
shanth_77

asked on

Moving to next page only if authorised.

Hi experts,
 I need to go to my second page only if i pass through my first page.If users directly go to 2 page they should not be allowed to do so.
I tried with the following code.
But if tells that the object does'nt support such action.
 my coding is as below. please help me out.......

Thanks in advance.
Shanth_77
 
<html>
<head>

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
<!-- Hide script from old browsers<br>
if(document.referrer ="C:\javascript\objbutton.html")

     location.href = "C:\javascript\SessionTry.html";


//-- Stop hiding script -->
</SCRIPT>  

</head>
<body>
HAI
</body>
</html>
Avatar of third
third
Flag of Philippines image

it should be,

<html>
<head>

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
<!-- Hide script from old browsers<br>
if(document.referrer=="C:\javascript\objbutton.html"){
  location.href = "C:\javascript\SessionTry.html";
}
//-- Stop hiding script -->
</SCRIPT>  

</head>
<body>
HAI
</body>
</html>
take note of,

if (x == y){ //comparing boolean expressions
  //statement here
}

also, take MORE attention on

Questions Asked 15
Last 10 Grades Given A B A B  
Question Grading Record 4 Answers Graded / 4 Answers Received

you have several aging open questions. if you continue this kind of attitude im very sure that you can never expect help from ME (and perhaps most of the experts). so to avoid this from happening, kindly settle those threads.
Avatar of shanth_77
shanth_77

ASKER

hi third,
 I tried with the above, now there are no errors. but even if i proceed via the objbutton page,it still gives me the alert of going to the home page. I feel the code of document is not reffered at all.I have modified my code a bit. please do have a look.

Thanks in advance.
shanth_77

<html>
<head>

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
<!-- Hide script from old browsers<br>
if(document.referrer=="C:\ksshanth\jsbishan\objbutton.html")
{
   alert(document.referrer);
   location.href = "C:\ksshanth\jsbishan\SessionTry.html";
}
else
{
alert("please visit home");
}
//-- Stop hiding script -->
</SCRIPT>  

</head>
<body>
HAI
</body>
</html>
hi third,
  even if i visit the home page, the sessionpage gives me an alert of "visit home".

I have taken note of the grades given.

thanks in advance.

it's not only the grades given, what im talkin about are the open questions. i have the answer but i can't give you not unless you settle your previous questions.

review the guidelines,

https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
Hi Third,
  I have settled almost most of my questions. Ive got 2 more questions without proper answers, others have been solved. Can u help me out now for the above question ?



ok, good to hear that! keep it up!

now the answer is here,

The referrer property only works when you use it on a live Web server. If you're designing your page offline, these scripts won't work until you actually post the page to a Web server.

http://www.netmechanic.com/news/vol4/javascript_no14.htm

in other words use,

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
<!-- Hide script from old browsers<br>
if(document.referrer=="http://ursite/objbutton.html")
{
  alert(document.referrer);
  location.href = "http://ursite/SessionTry.html";
}
else
{
alert("please visit home");
}
//-- Stop hiding script -->
</SCRIPT>  



ASKER CERTIFIED SOLUTION
Avatar of wolfpackinc
wolfpackinc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michel Plungjan
So I right-click, see the name and do a
javascript:window.name="android"; window.location='page2.html'
;-)

Michel
And when you publish it, this
="C:\javascript\objbutton.html")
will be totally useless. It's a reference to your hard drive, not where the file is on the server.

This really isn't the way to do what you want. If you want to keep people out of the second page, you need to set a cookie on the first one and check for it on the second.

Cookies are NOT the simplest things to write for a beginner. YOu can get lots of various cookie scripts at www.javascriptsource.com
>>So I right-click, see the name and do a
>>javascript:window.name="android"; >>window.location='page2.html';

True but it depends on what reasons he wants to start with the first page...

For example I have a first page that redirects according to browser etc. user is using and I want them to go to the proper page and not directly to one of them.


>>If you want to keep people out of the second page, you
need to set a cookie on the first one and check for it on the second.

This sounds like a good idea

hi ,
 I works well. But i was slightly confused of how window.opener works because, in my case its always null.
Please explain ur coding for my clarity.
Thanks a lot.
Shanth_77