By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

InnerHTML Caching

P: 83

I have an asp page with for example:

<div id="introText"></div>

next to this is a button. when then user clicks on the button I fire some javascript

function doThisWhenButtonClicked() {

document.getElementById('introText').innerHTML = "Hello Everybody";


so once the button is clicked I see "Hello Everybody" inside the div.

No problem so far.

However if i visit another page on my site and then click the back button to return to the page "Hello Everybody" has gone - ie it's not cached i assume ??

Can anyone help - i'm using Chrome.

Thanks on advance
Dec 6 '11 #1
Share this Question
Share on Google+
12 Replies

Expert Mod 5K+
P: 8,639
afaik, results of JavaScript operations ain’t cached (it would use way more memory than saving HTML source code and render the page anew)
Dec 6 '11 #2

P: 83
sorry don't really understand. so if they are not cached why do i see that behaviour and how can i resolve it ?
Dec 6 '11 #3

P: 638
what do you want to resolve in it ? so you want the browser to remember what ever was inside the div should be there if i click back in the browser after visiting any other page?
regards, why would you want to do that and why you want to use javascript only for that work?
Omer Aslam
Dec 6 '11 #4

P: 83
ok bit more detail - my site lists property. On each advert there is an 'add to your selection' link. When they click on this the text is changed into 'The advert has been added to your selection' (This is the text inside the div). They then click on the tab 'My selection' where they see the advert selected. they then go back to the listing by clicking on the back button and see the advert they selected now says 'add to your selection' which is clearly confusing for them.

hope this makes sense and gives a bit more insight into why I'm trying to solve this.
Dec 6 '11 #5

Expert Mod 5K+
P: 8,639
why would they need to go back to see the result of what they just did?
Dec 6 '11 #6

P: 83
they're not going back to see what they did especially, it's just that they return to the listing page to carry on looking down the adverts. it's not something that happens a lot but it does happen and it causes problems (these are paying customers) so it would be nice to find a solution
Dec 7 '11 #7

Expert Mod 5K+
P: 8,639
then you need to disable either caching or going back, because HTTP is a stateless protocol that doesn’t automatically update itself.
Dec 7 '11 #8

P: 83
yes thanks but i realise that. going back can't (or shouldn't) be disabled and disabling caching will cause other problems i'm sure (also not great practice). i was hoping there was another solution but maybe not :(
Dec 7 '11 #9

Expert Mod 5K+
P: 8,639
you could tell your customers that they have to refresh the page in case they were going back and want to see their advert added. (I mean, there a a lot of not tech-savvy people, but going back in the browser and expecting to see changes made otherwhere …)
Dec 7 '11 #10

P: 83
yes its'a good thought but I have plenty of experience with people seemingly unable to read instructions ;) ! A tech soln would be the best if possible
Dec 7 '11 #11

Expert Mod 15k+
P: 16,027
There are one or two possibilities, e.g. adding # (hash) to take back control of the back button. This is usually used for Ajax, but you could possibly use it here, but I wouldn't know how useful it'd be and if it would affect anything else in your site.

Another possibility is a periodic Ajax call to update the listing. You could make it more "intelligent" by only updating if there's been a change after the initial request.

I'm not saying any of these are good solutions or even if they'll work, but just a couple of ideas to explore.
Dec 7 '11 #12

Expert Mod 10K+
P: 12,430
What if you used the onload event to update the data?
Dec 7 '11 #13

Post your reply

Sign in to post your reply or Sign up for a free account.