Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In a stew with cookies - multiple copies of same cookie etc?! 1

Status
Not open for further replies.

JavaSprout

Programmer
Jul 31, 2001
30
BE
I have various problems in getting the following prototype to work:


The idea is simple; create a number of pages which follow the normal (x,y) co-ordinate system and allow navigation between them using cookies.

The problems are:
a) Page disappearing; when I click on 'Show Cookie values', not only does it show the value of the cookies but it changes page. Why?! It does not do it when testing on my hard drive.

b) Multiple cookies! When I run the example more than once (or move within the pages with North, South, East, West keys), and then click on 'Show Cookie values', it shows me more than one version of xpos and ypos!! Why? Shouldn't I only have 1 cookie called xpos and 1 called ypos? This I think is part of the next problem...

c) Out of sync 'GridRef' with real page ref. Often (except very first time) the heading will show, for example, 'GridRef is x0y-1' while the page URL will clearly show as, for example, 'http:/ /x0y0/...'. Why?!

Thanks a lot for any help you can give. I'm going crazy on this one.


Hugh Prior
 
Why are you using cookies?

If all you need this to do is 'move' n/s/e/w couldn't you document.write the correct links after testing the current location?

Cookies are evil and cannot be relied on! Well... maybe not evil, and you probably could use them for the most part... but isn't my idea at least feasible? :)

Just a few thoughts!

-gerrygerry
 
Thanks gerrygerry. Nice idea. I'll look into it.

Why am I using cookies? I'm new to JavaScript and it just seemed conceptually the right thing to do to use cookies to solve the problem (since cookies were introduced to keep state and this is a problem of knowing the current state). I've already picked up from reading various posts, that cookies are a nightmare though, so I like your idea.

If I understand your solution correctly you propose:
1) pull the URL of the current page:
e.g. myurl = document.location
2) Parse it to get the current x,y
3) Generate dynamically the N/S/E/W links:
Code:
<script>
// This will be in my table element, for 'North'
<a href='&quot; + my_y_plus_1 + &quot;'&quot;>N</a>
</javascript>

Hugh Prior (alias JavaSprout)
 
When you purge the x/y values, make sure you get them as an integer... getting them as a string could make things much more difficult.

About your link:
Code:
<script>
document.write(&quot;<a href=\&quot;/x=&quot;+x+&quot;y=&quot;+y+&quot;/index.html\&quot;>N</a>&quot;);
<script>
would give you the equivalent of:
Code:
<a href=&quot;/x=?y=?/index.html&quot;>N</a>
(the relative path to your xy directory index file)

Is CGI a possibility here? This might be alittle easier to do with perl than with JavaScript. Not saying it can't be done with js, just a thought.
 
gerrygerry

Yes, I had this problem of string vs int before with the cookie solution, trying to add &quot;1&quot; (string) to 2 (int) and got &quot;21&quot; instead of 3.

Your idea made me wonder whether I can 'pass' whatever I want to the other page by setting the page string, e.g.

Code:
<a href= .../map.htm?xtra1=1234,xtra2=xyz>

I have of course seen such type of URL's many times in the browser but always thought they were ASP or JSP.

If I can pass things like this, then how do I receive them at the other page?

Thanks.

JavaSprout
 
This can be done with javascript, and actually, IE6 is going to try and use more, but it's still is only supported in newer browsers. I think this is how it works:
Code:
var x = location.search.substring(1, location.search.length);
var y = location.search.substring(2, location.search.length);
Throw some alerts in the make sure your getting what you want. I haven't used this much...
 
Whoops, didn't mean to submit yet! :)

put this in a page, and call it like so:
Code:
mypage.htm?x=1&y=2

this (with the code in last post) should be the same as saying x=1;y=2; in your script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top