-
- 49 Posts
Hi, i have a snippet with code to generate a popup in any given page. this code
$ran = array(25315,23057,25316,7279,4599,23574);
$randomElement = $ran[array_rand($ran, 1)];
this randomElement is what im gonnna use to do the logic.
is not working properly. $randomElement is a random number from the array of 6 elements. the thing is that i can see that the page is generating the popup correctly when im logged in to modx, but if not(example, i opne the same page in Firefox, no logged in to modx) the page is not generating the random code, just the same every time i refresh the same page.
when i enter another different url, it generates well until i refresh the same page.
snippet is uncached !randomsnippet.
and same with the chunk
[[!$mainchunk]]
[[!randomsnippet]]
thanks in advance
-
- 24,544 Posts
That sounds like the browser cache. Is there a way you can cache-bust by adding a query string to the end of the URL like this?
your/url/? &cb="some_random_number"
If not, you could do something like this:
https://stackoverflow.com/questions/49547/how-to-control-web-page-caching-across-all-browsers
-
- 24,544 Posts
Adding ?cb=## where ## is a number you change, or the current timestamp works for me, though TBH I'm not sure how to accomplish that in code in your situation.
One way might be to use a snippet in side your URL:
<a href="your_url?cb=[[time]]">
/* time snippet */
return time();
I think it's possible to alter the URL with a plugin, but I can't remember how to do it.
Another way to go, since you're creating a popup, would be to do the random selection in your JavaScript.
-
- 49 Posts
mhm, nope, i attached a random number to my url, to my snippet/chunk as a param, but it doesnt work.
it works if im logged in to the manager and go to the site to check that everything is ok. if i log out, the random number is there, but even if ai refresh the same page a million times, the popup is not changing unles i go to another page... thanks for the help