Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi..
i have an iframe on my web page. i am displaying different pages dynamically on my iframe.
now i want to implement back/forward button for iframe contents only.
how should i do this?
thanks
Posted

We have discussed this earlier[^], haven't we?

Once again, in order to implement a back/forward button, you need to keep a track of all the URL's in sequence. It would be kind of a URL stack. Now, have two buttons. Back would traverse you to previous URL from current and forward would take you to next one.

Now, please give it a try! I don't see why or what's unclear here and stopping you.
 
Share this answer
 
Comments
niravsahayata 24-Dec-10 3:06am    
but in my iframe i am displaying pages from some other websites,i am not displaying pages from my local machine, so how i can i have that url ?
history.current/previos/next are not working.

i have tried this window.frames.frameID.history.forward(); but it throws error that access is denied
Sandeep Mewara 24-Dec-10 3:11am    
When you are working with iframe, how can you expect that browser history keep a track of the urls and history.forward and back woruld work.

What you need is to keep a track of URL's yourself. Whenever you open/navigate to any URL inside the Iframe, you manually via code need to track it and keep it.
JavaScript
var urlList = new Array();
var pos = 0;
function goToPage(pageUrl)
{
    urlList[urlList.length] = pageUrl;
    pos = urlList.length - 1;
    document.getElementById('iframe').src = pageUrl;
}
function goBack()
{
    if (pos > 0)
    {
        pos--;
        document.getElementById('iframe').src = urlList[pos];
    }
    else
        alert('You reached the first page of history');

}
function goForward()
{
    if (pos < (urlList.length-1))
    {
        pos++;
        document.getElementById('iframe').src = urlList[pos];
    }
    else
        alert('You reached the last page of history');
}


Use the function goToPage(pageUrl) to navigate the page in iframe, goBack function to navigate back and goForward function to navigate forward.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900