Help - Search - Members - Calendar
Full Version: Blocking a page change.
HTMLHelp Forums > Programming > Client-side Scripting
rhodge
Ok, say I have a website with 3 pages and all 3 pages there is a set of links on them.

pages 1 and 2 both have links to page 3 on them but i only want people to be able to access page 3 from page 2 for some very good reasons. but i don't want to have to just get rid of the link on page 1.

is there a way that i can block page 3 being accessed from page 1? it would be even better if i could have some form of pop-up dispaly a message when the link is clicked to explain why access has been denied.

if there's no way to do that i'm open to sugestions on how i can
Brian Chandler
The purpose of a link is to give immediate access to another page. If you do not want a link from page 1 to page 3 do not put one there. It's as simple as that.

First silly idea:
On page 1 replace <a href="page3.html">Page 3</a> by

<a href="notpage3.html">This is not a link to page 3</a>

Then notpage3.html is a page that says:

This is not page 3. Go back to <a href="page1.html">Page 1</a>.

Silly ideas 2, 3, 4, and 5:

Um well, think of these for yourself.


rhodge
Thanks for the response. The links are actually elements in a cookie and as far as I can see can't be changed from page to page so the ideas you have sudgested wont work sadly.

Don't know if you've ever used gmail but some times when you leave the site a pop up comes up saying "are you sure want to leave this page" Something like that would be good but i'm bamboozled by the code for the gmail site.
Brian Chandler
QUOTE(rhodge @ Jan 12 2009, 09:54 PM) *

Thanks for the response. The links are actually elements in a cookie and as far as I can see can't be changed from page to page so the ideas you have sudgested wont work sadly.

Don't know if you've ever used gmail but some times when you leave the site a pop up comes up saying "are you sure want to leave this page" Something like that would be good but i'm bamboozled by the code for the gmail site.


Who wrote the page? If you did, rewrite it to what you want. If you are getting the pages as output from some magic "Solution", then well, lie back and enjoy them, because it's outside your control.

A link can't be an "element in a cookie" in any obvious sense. It's hard to guess quite what this might mean, without seeing th page.

If you just want a "warning", use javascript with an onclick handler on the link. But if you can't change (1) to (2) - as I suggested - I can't see how you'll be able to change it to (3) either...

(1) <a href="page3.html">Page 3</a>

(2) <a href="notpage3.html">Not page 3</a>

(3) <a href="page3.html" onclick="[[alertbox]]">Page 3</a>
Christian J
QUOTE(rhodge @ Jan 12 2009, 05:07 AM) *

is there a way that i can block page 3 being accessed from page 1? it would be even better if i could have some form of pop-up dispaly a message when the link is clicked to explain why access has been denied.

You can let JS check the page's file name, but this is easily circumvented and will not stop search engines or users without JS. You may also check the HTTP referrer, but again that can be spoofed.

QUOTE
The links are actually elements in a cookie

Come again? Or do you mean the links are included from an external file? unsure.gif
rhodge
Ok I should start again and make myself more clear.

The website was built my me from ground up. It's a kind of game that has collectable items that are sent to an inventory for when they are needed. These items are stored in a cookie so they stay in the inventory no matter what page the user is on.

You need to use the items to get past obsicals in the game (use the key to open the locked draw, blah blah blah) and that's why i need them as links. But i only need them as links on some pages.

At the moment they're not links and instead i'm using an empty div positioned over where the items are when they need to be clicked. This isn't ideal though because you can bypass the items alltogether by just cliking the div.

Webpage
Brian Chandler
I can't really understand your description (at least the bit about empty divs), but it sounds as if you have just designed it wrong.

Suppose 'cookie' includes a list of the 'items' the player has. You want to provide a 'door' iff the user's cookie includes the magic 'key', and the 'door' should lead to the 'maiden'. Something like that?

Then the program that generates the first page says (in pseudocode):

if('cookie' includes 'key')
showlinkto('maiden');

i.e. conditionally writes the link. But you only want the link to be accessible if the 'item' is present. So at the beginning it checks that access is valid (you need to write a general function for doing this)

if(!check('cookie' includes 'key'))
showfailurepage()

Where showfailurepage is a general error message page, with a link back etc.

Does this help?


Brian Chandler
QUOTE(Christian J @ Jan 12 2009, 10:29 PM) *

QUOTE(rhodge @ Jan 12 2009, 05:07 AM) *

is there a way that i can block page 3 being accessed from page 1? it would be even better if i could have some form of pop-up dispaly a message when the link is clicked to explain why access has been denied.

You can let JS check the page's file name, but this is easily circumvented and will not stop search engines or users without JS. You may also check the HTTP referrer, but again that can be spoofed.


I really don't think this makes any sense: what can javascript "check" that couldn't have been checked already before sending the page?

If you mean on the sending page, then how is

<a href="page3.html" onclick="if(X) changelinkto('notpage3.html')">

better than

<a href="notpage3.html">

It _might_ be, if the condition X were something interesting, but spot that X is vacuously true.

If you mean on the destination page, then you just need to check the cookie (because the player is allowed to 'maiden' IF they have 'key', whether they climbed the ivy and jumped through the window, or just walked in through the front door), and it is better to check the cookie before sending the page.

Brian Chandler
Sorry! Part of this is not clear...

QUOTE(Brian Chandler @ Jan 13 2009, 01:08 PM) *

I can't really understand your description (at least the bit about empty divs), but it sounds as if you have just designed it wrong.

Suppose 'cookie' includes a list of the 'items' the player has. You want to provide a 'door' iff the user's cookie includes the magic 'key', and the 'door' should lead to the 'maiden'. Something like that?

Then the program that generates the first page says (in pseudocode):

if('cookie' includes 'key')
showlinkto('maiden');

i.e. conditionally writes the link.

*****
But you only want the link to be accessible if the 'item' is present. So at the beginning it checks that access is valid (you need to write a general function for doing this)
*****
SHOULD BE
*****
But you only want the destination page to be accessible if the 'item' is present. No need to worry about "refere ( r ) ers"; at the beginning of the destination page (as on all other pages except START, of course) you check that access is valid by looking at the cookie (you need to write a general function for doing this)...
*****


if(!check('cookie' includes 'key'))
showfailurepage()

Where showfailurepage is a general error message page, with a link back etc.

Does this help?

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.