Keep a randomly generated HTML background static for the duration of a session?
I have a wordpress site that generates a random background on the homepage. Each time the user clicks through various parts of the site, I would like to keep this background the same until the user clicks on the homepage again.
I have thought of a number of possible solutions:
AJAX calls loading the content of various clicks into a div (not ideal as it gets complicated quickly with trying to manage friendly urls, plugins that call their own a开发者_JS百科jax data etc)
A cookie that saves the background html into it and expires quickly or when reloading the homepage.
A POST variable that holds the background html between the various parts of the site.
The primary goal is to keep a background that is randomly generated on the homepage but remains the same while using the website. Can anyone recommend a better solution?
Thanks a lot!
you could either do it via cookies or GET Parameter. The cookie solution takes more effort on JavaScript side. And some users do not like cookies, but that should not be a big deal.
You could prepare all the impacted links like so http://www.example.com?bgimg=bigblackdog
and then set the image via wordpress php code or maybe js if you want to.
精彩评论