views:

52

answers:

2

How to "implement" back and forward buttons in an iframe with JS?

+5  A: 

Use the window.history object.

// For the current window
window.history.back();     
window.history.forward();

// For an iframe's window
iframe.contentWindow.history.back(); 
iframe.contentWindow.history.forward();

or

iframe.contentWindow.history.go(-1); // back
iframe.contentWindow.history.go(1);  // forward

https://developer.mozilla.org/en/dom/window.history

Andy E
The forward button doesn't work.(Firefox 4.0 and 3.5)
lam3r4370
+2  A: 

Button within frame:

<input type='button' value='Back' onclick='history.back()'>

Button within parent frame:

<input type='button' value='Back' onclick='frame_name.history.back()'>
Riateche