Javascript top level object - window doesn't seem to cut it
Hey 开发者_StackOverflow社区JS gurus... I am juggling w/ some crazy weird google map stuff. I need to store 2 numbers (lat/long), click on a pin, and on the new page, use these numbers.
So I tried to store these in the good ole' window:
window.lat = ...; window.lng = ...;
however, the window after the click on the map is not the same window that holds our lat, lng.
So the question is: does our 'new' window hold a reference to the one that has out lat/lng? I tried window.top, window.parent, window.frames, it's all equal to window...
Alternatively, where can I store those values to be able to restore them later?
You cannot persist Javascript variables across pages.
Instead, you should use a cookie.
You need to look at cookies/sessions to hold values over different pages:
JavaScript Cookies: (note i've never actually used these, but presume this info is up to date) http://www.quirksmode.org/js/cookies.html
Sessions: (PHP as example, but all server-side languages support sessions) http://www.tizag.com/phpT/phpsessions.php
Either you have to use Cookie or you should pass these numbers as URL variables. Every time you load the Window the complete DOM be written again, that's why your variables no more exist after page reload.
精彩评论