Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Moving to next page only if authorised.

Posted on 2002-04-03
13
Medium Priority
?
171 Views
Last Modified: 2011-10-03
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>
0
Comment
Question by:shanth_77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 30

Expert Comment

by:third
ID: 6916900
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>
0
 
LVL 30

Expert Comment

by:third
ID: 6916911
take note of,

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

Expert Comment

by:third
ID: 6916921

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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:shanth_77
ID: 6916923
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>
0
 

Author Comment

by:shanth_77
ID: 6916937
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.

0
 
LVL 30

Expert Comment

by:third
ID: 6916962
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,

http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
0
 

Author Comment

by:shanth_77
ID: 6917148
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 ?



0
 
LVL 30

Expert Comment

by:third
ID: 6917165
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>  



0
 
LVL 1

Accepted Solution

by:
wolfpackinc earned 200 total points
ID: 6917253
Put in header of the page to normally start from:

<SCRIPT LANGUAGE="Javascript">
<!--
self.name = "android"
-->
</SCRIPT>

Put in header of page you don't want accessed directly:

<SCRIPT>

<!--
//specify valid referrals for script to accept
//if you wish an entire domain to be valid, enter that (ie: "javascriptkit.com")
var validreferrals="android"
if (window.opener == null){
alert("You can not access this page directly!\nYou will now be redirected")
window.location.replace("Page1.html")
}
else if(window.opener.name != validreferrals){
alert("You can not access this page directly!\nYou will now be redirected")
window.location.replace("Page1.html")
}
//-->
</SCRIPT>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6917615
So I right-click, see the name and do a
javascript:window.name="android"; window.location='page2.html'
;-)

Michel
0
 
LVL 19

Expert Comment

by:webwoman
ID: 6918153
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
0
 
LVL 1

Expert Comment

by:wolfpackinc
ID: 6922285
>>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

0
 

Author Comment

by:shanth_77
ID: 6923660
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

0

Featured Post

Hire Technology Freelancers with Gigs

Work with 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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

705 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