Internet Explorer showing blank page after back button with dynamic content

I’m having a strange problem with Internet Explorer when using dynamic content. Here’s what happens:

I have JavaScript code that creates HTML elements based on user interactions. When the page first loads, my script takes an empty div and fills it with a list and some content. Users can click on items to load more data dynamically.

The issue occurs when users leave the page and then use the browser’s back button. In IE, I get a completely blank page where the dynamic divs should be. However, in Firefox, Safari, and Opera, everything works fine - the page either reloads properly or shows the last state with all the dynamic content still there.

Has anyone encountered this behavior before? I’m not sure if this is related to IE’s caching or how it handles dynamically generated DOM elements. Any suggestions would be really helpful.

Classic IE caching problem - I’ve hit this so many times. IE handles dynamically generated content weird compared to other browsers, especially with the back button. It caches the original DOM state before your JavaScript runs, so hitting back just restores that empty div instead of keeping your dynamic changes. I got around this by adding a pageshow event listener. It detects when the page gets restored from cache and re-runs your content generation script. You could also try setting cache control headers or using onbeforeunload to flag when the page needs rebuilding on return. Bottom line: you need to force IE to re-run your JavaScript instead of just showing cached static HTML.

same thing happened to me too! try using window.onpageshow instead of onload for dynamic stuff. IE can get confused with that back button and doesn’t trigger the usual events. also, watch out for your AJAX calls 'cause IE’s caching can mess those up too!

This drove me crazy for weeks last year. Here’s what fixed it: I added a simple state check with a hidden input field that gets populated when the dynamic content loads. On page load, I check if that field exists and has a value. If it does, I know they hit the back button and trigger the content regeneration. IE basically pretends dynamically created elements never existed once you navigate away - other browsers actually preserve the modified DOM state. You could also try using the onunload event to set a sessionStorage flag when dynamic content is present, then check for that flag when the page initializes.

This topic was automatically closed 6 hours after the last reply. New replies are no longer allowed.