开发者

Firefox back button vs iframes

开发者 https://www.devze.com 2023-02-15 19:56 出处:网络
In Firefox if the window.location of an iframe is changed, this gets populated to th开发者_开发百科e history of the top level window.

In Firefox if the window.location of an iframe is changed, this gets populated to th开发者_开发百科e history of the top level window.

If the user now clicks the browser back button, the contents of the iframe will change rather than the browser going back to the previous HTML page.

This is totally wrong for some architectures.

Is there any way with JavaScript to prevent Firefox (3.x) from doing this?

(Please stick to just this question, not why/when/how iframes versus other techniques should be used.)


Use .location.replace


I have the same issue and was researching possible ways around it when I read this. I don't know if you solved the problem, but I think I'm going to use the unload event in the IFrame'd window to notify the parent window when it's unloaded.

If the iframe is closed by a 'valid' method, a variable is set at the parent to say the iframe is expected to unload

If the parent reloads / changes the src of the iframe a variable is set to say the unload is expected

If an unexpected unload happens in the iframe I assume it was the back button and update the parent page accordingly (e.g. jump another step back in the parent's history, or do something else).

The only ugly case here is if the parent page is unloaded and the iframe also throws unload - depending on how quickly the parent page changes you might get a race condition where the parent's iframe unload handler is or isn't fired.

0

精彩评论

暂无评论...
验证码 换一张
取 消