Closed Bug 343258 Opened 18 years ago Closed 18 years ago

scripts not executing when using back button

Categories

(Core :: DOM: Navigation, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: galantonp, Unassigned)

References

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4

If a page contains scripts they will not be executed if the user navigates away from the page and the returns to it by using the back button. If the user returns to the same page using a link, the scripts execute correctly.

Reproducible: Always

Steps to Reproduce:
1. page1.html contains a script (like alert("i'm a script") and a link to page2.html
2. navigate from page1.html to page2.html using the link on page1.html
3. hit the back button. page1.html is displayed, but the script does not execute

Actual Results:  
page is displayed without executing any scripts

Expected Results:  
page is displayed and scripts are executed just like when the pages is accessed by using a link

I'm not sure if this behaviour is intentional or if it is a bug. There are cases when scripts should run only once, and there are cases when scripts should run every time the page is displayed, regardless of the way they have been accessed (link or back button). In my case, the script manipulates the layout of the page. It is displayed correctly when the page is accessed by a link, but if the user returns to the page by using the back button, the scripts do not execute and the layout remains in the last state. 

For instance, at some point a table row is made blue by a script. Onmouseover it becomes red. onclick it loads another page. If the user hits the back button, the row is still red, because the script that made it blue does not execute.

There may be a meta tag that prevents this behaviour that I am not aware of.
Component: General → History: Session
Product: Firefox → Core
QA Contact: general → history.session
Version: unspecified → Trunk
This is expected behavior with bfcache, and I can't imagine any other behavior being both fast and correct on most sites.  (For example, executing onload again, on a DOM that has already gone through an onload event, would break many sites.)  See http://developer.mozilla.org/en/docs/Using_Firefox_1.5_caching for how pages can detect or disable bfcache if this default behavior isn't ideal for them.

This is similar to bug 312816 but not similar enough to be a dup, so I'm marking it as invalid.
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → INVALID
(In reply to comment #1)

I knew it there had to be some meta tag to prevent caching. I was mislead by the fact that while testing in other browsers the scripts executed when loaded from cache and assumed this was the right behaviour. Glad to learn about the new pageshow event too. Cheers.
Component: History: Session → Document Navigation
QA Contact: history.session → docshell
You need to log in before you can comment on or make changes to this bug.