0

I have multiple iframe on page but only one should be active at the moment. So when I navigate in frame1, frame2, frame3 all works good. There is main menu to switch iframes. Now, the problem is when i hit back button in browser, it will always do back action in iframe that has been last navigated in. I need to do that in "active" one. Currently I only hide inactive iframes but I need to disable them completely. I need multiple iframes so, when I switch between menu options, navigation in each one is preserved. Is there a way to totally disable iframe so it behave as it doesn't exists on page but not to unload it's content.

1 Answer 1

0

I am not sure about disabling iframes in your case. You could implement something using javascript - for example buttons that trigger an event on a specific target iframe using something like:

<a target="the_active_iframe" href="nav();">Link to a location</a>
<iframe name="the_active_iframe"></iframe>

and in javascript function

nav() {
  window.navigate("new location",target="the_active_iframe");
}

you could implement back and forward navigation in a similar way:

Back and forward buttons in an iframe

Another idea that could work would be to use some hover or onmouseover functionality, to define which frame is active and use window navigation events to that specific frame, but I would use buttons .... it seems less confusing to me.

Edit: if you want to do it like you say ... you would need to save the history for each iframe separately into a variable in javascript ... and on mouse-over (or something like that) rewrite the window.history with the current-iframe history ... I have never tried to do something like this ... but it might work.

Here you can find how you would save the history of a specific iframe: Track only iframe history

Then what you need to do is only overwrite the window.history ... on mouse-over for an iframe to the respective iframe navigation history.

5
  • Yes, but I need to handle browser built in back button, it would not be a problem to add my own. Is there way to hook on that buttons or something. Apr 19, 2013 at 9:23
  • you would need to save the history for each iframe separately into a variable in javascript and on mouse-over or something like that rewrite the window.history with the current iframe history Apr 19, 2013 at 9:43
  • Hm, in my case (ff, chrome) window.history has all iframes history combined. Every iframe has the same history as main page. Am I missing something?Is that even possible? Apr 22, 2013 at 12:02
  • yes ... this is the problem, the main window.history is saving all changes ... that is the same for all iframes ... but when you are in an iframe (you can detect your current position) and you just have to save the occurring navigation history changes into a javascript variable, that you use to overwrite the window.history, you should make a variable for each iframe, and when you are over an iframe, you overwrite the window.history with the variable where you saved only the history changes for the respective iframe Apr 22, 2013 at 12:29
  • Hm, I have tried that, no success. Can you provide some basic example please? Apr 22, 2013 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.