OZONE Asylum
Forums
DHTML/Javascript
Creating "Buffers" - problems with history and coookies
This page's ID:
28018
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
WarMage: Thanks for the interesting information. I think my method will need garbage collection too, though not as much. I added a field to the buffer table called "bufferLast" thats a unix timestamp updated every time the buffer table is read. I was thinking of deleting all buffers older than a day or so. Another thing I expirimented with was keeping all the open bufferids in a comma seperated string in the cookie most recently viewed first. If I can get the base mechanism working, I may try to finish that :-) [b]I was hoping an "excercise in theory" would be enough, but I guess not. :) Here is my current JS Code (mostly an updated version of "attempt 3"):[/b] The only problem with this script is that the cookie called "atibuf" is NOT sent to the "link target" page (the page the link clicked points to) as far as I can tell. Once a linked is clicked ON that subsequent page, the cookie is sent as it should be. [code] <script type="text/javascript"><!-- var ati_buffer = "'.$_SESSION['bufferId'].'"; if(history.length == 1 || ! ati_buffer) { ati_buffer = ""; pool = new String("abcdefghijklmnopqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); var i = 0; while (i < 15) { rand = parseFloat(Math.random()) * parseInt(pool.length); ati_buffer += pool.charAt(rand); i++; } } function ati_buffer_finish() { //Called OnUnload document.cookie = "atibuf=" + ati_buffer + "; path=/; domain=.'.$_SERVER['HTTP_HOST_TOP'].'"; }; --></script> [/code] Basically, I am using the cookie as a "very short term" variable preservation technique. Is there some other mechanism I could use for this? Can JS modify post data or set http headers on the fly? (Get data is excluded, as it will mess up all my beautiful URLs) -Robur [b]EDIT:[/b] Sorry... I just had to update my code... :) The new version almost supports keeping a list of the current buffers, but I need a way to detect if the user clicked a link or closed the window. If the window is being closed, I will remove the current bufferId from the list. It almost seems like I should create two cookies, one with the current buffer that expires instantly and one with all the other buffers that doesn't ecxpire, and then delete all the buffers from the database that don't match either cookie for the current sessionid... will have to play around with that. [i]It almost seems it's so complicated that i'd be better to just delete the old buffers - after all, I will have to do that anyway because lots of my visitors are using windows so their browsers are sure to crash sometimes :) (just kidding)[/i] [code]<script type="text/javascript"><!-- //Init Vars var ati_buffer = ""; var bufferString = ati_getCookie("atibuf"); var bufferCookie = ""; if(history.length == 1) { pool = new String("abcdefghijklmnopqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); var i = 0; while (i < 15) { rand = parseFloat(Math.random()) * parseInt(pool.length); ati_buffer += pool.charAt(rand); i++; } } else ati_buffer = "'.$_SESSION['bufferId'].'"; //Set cookie function ati_buffer_finish() { //Called OnUnload if(bufferString) var bufferSplit = bufferString.split(","); for (i=0; i<bufferSplit.length; i++) { if(bufferSplit[i] != ati_buffer) bufferCookie += "," + bufferSplit[i]; } } document.cookie = "atibuf=" + ati_buffer + bufferCookie + "; path=/; domain=.'.$_SERVER['HTTP_HOST_TOP'].'"; }; //Helper Functions function ati_getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(";"); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==\' \') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return false; } --></script>[/code] [small](Edited by [url=http://www.ozoneasylum.com/user/5444]robur[/url] on 06-01-2006 05:01)[/small] [small](Edited by [url=http://www.ozoneasylum.com/user/5444]robur[/url] on 06-01-2006 05:06)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »