persist value between two pages using javascript [duplicate]

孤人 提交于 2019-12-10 10:47:37

问题


i have a one html page in which i am storing few user selected values now and want to use these values on another html page.

i am using jquery in my module and i have already tried window.name and window.localStorage but they don't persist values between two pages.

so please help me to solve this problem.


回答1:


If you don't want a cookies--and if you're directing from the first page to the second, how about passing the values as GET variables to the next page:

http://example.com/newpage.html?var1=blah?var2=blerg

then you can access that data with window.location.search.




回答2:


You could use the "hash":

http://my.app.com/page2.html#name1=val1&name2=val2

The hash would be ignored by the server, keeping things "clean". The second page can read the hash from

window.location.hash

and then parse out the name/value pairs with some simple string/regexp/array manipulation.

If you wanted the hash to be "hidden", your second page could also then remove the hash from the URL - this would not result in another trip to the server - changes to hash only result in browser/client side behaviour.




回答3:


If it's just a few values, how about cookies?




回答4:


Store the value inside a cookie on the first page and and retrive it on the second. Its very easy with the Jquery Cookie plugin http://plugins.jquery.com/project/cookie




回答5:


You would have to try and use cookies (assuming users are nice enough to enable those). Here is a very useful link: http://www.w3schools.com/JS/js_cookies.asp




回答6:


Finally i got pretty cool solution on

http://plugins.jquery.com/project/DOMCached



来源:https://stackoverflow.com/questions/2477784/persist-value-between-two-pages-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!