Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2012, 03:35 AM   PM User | #1
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
history.back() in iframe

I'm having a nightmare trying to code a simple back button in an iframe. A Fancybox iframe to be exact. Imagine a site which can open up links in a Fancybox iframe as a preview. The user could open a link and keep clicking inside the iframe. I want them to also be able to click Back inside the iframe.

Also, I don't want to use an onclick handler, I just want a solution something like this:

Code:
function go_back() {
    if( this_is_an_iframe === true ) {
        history.back();
    } else {
        window.history.back();
    }
}
If I use window.history.back() for everything then it works ok on some browsers, but not on others. Some browsers (including mobiles) will just go back the entire page (not the iframe). I'm sure there's a solution to serve slightly different code when in an iframe.
johnsmith153 is offline   Reply With Quote
Old 12-03-2012, 06:13 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Going back relies on the way the browser uses the history list. It isn't going to make any difference where or how you call back it will go back one entry in the list that the browser has saved.

You can control whether new pages/frames get added to the list or overwrite the prior entry but that's about as much control as you get.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:35 PM.


Advertisement
Log in to turn off these ads.