[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
HowToJavaScriptCreateBackButtonInIframe

How to create a Back button for an Iframe?

When you load content in an iframe, it may also contain links you want to navigate back / forward, just like you do using the browser's Back and Forward buttons.

The window object's history object keeps the URL of all visited pages you have opened in your browser.

There are two ways of simulating the Back button:

window.history.go(-1)
window.history.back 


There are two ways of simulating the Forward button:

window.history.go(+1)
window.history.forward 


Create an iframe and give an id/name attribute to it.

<iframe align="center" width="50%" height="50%" src="pic1.jpg"  frameborder=yes name="myIframe" id="myIframe"> 
</iframe>


Place this form in the main document or frame.
<form>
<input type="button" VALUE="&lt; &lt; &nbsp; Back &nbsp;"  onClick="history.back()"> 
<input type="button" VALUE="&lt; &lt; &nbsp; Previous"  onClick='window.frames.myIframe.location.href="pic1.jpg"'> 
<input type="button" VALUE="&nbsp; Next &nbsp; &gt; &gt;"  onClick='window.frames.myIframe.location.href="pic2.jpg"'> 
<input type="button" VALUE="Forward &nbsp; &gt; &gt;"  onClick="history.forward()"> 
</form>


Adding the Next and Previous buttons are used to trigger off the paging effect of the browser.

Related threads:
Creating a Back button in a iframe

Java Script FAQ

last edited (April 19, 2004) by leeos, Number of views: 3247, Current Rev: 5 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.