PDA

View Full Version : Best solution for browser back button on a page using iframe content?



darnen101
02-01-2011, 03:05 PM
It's a well documented issue-
when you have a page that contains an iframe, and then navigate inside the iframe, hitting the browsers back button will only affect the contents of the iframe and not the entire page. I've been searching all over for solutions and cant find one that works for my current implementation.
Anyone have any suggestions?
Here is my code:
js


function ShowPage(frame)
{
frames[0].location = frame+'.html'
frame.contentWindow.location.replace(newUrl);
}

Buttons that change the contents of the iframe

<div id="thumb1"><a onmouseover="ShowPage('frame1')"onclick="ShowPage('frame1')" target="mainbox"></a></div>
<div id="thumb2"><a onmouseover="ShowPage('frame2')"onclick="ShowPage('frame2')" target="mainbox"></a></div>
<div id="thumb3"><a onmouseover="ShowPage('frame3')"onclick="ShowPage('frame3')" target="mainbox"></a></div>

and then the iframe itself

<iframe src="frame1.html" type="text/html" style="border-width:0; border-style:hidden;" transparency="true" name="mainbox" frameborder="0" scrolling="no" width="700" height="807">
</iframe>

Kor
02-01-2011, 03:13 PM
What about using the native javascript object/property history ?
http://www.w3schools.com/jsref/obj_history.asp
Try to see if the contentWindow reference object supports that property

darnen101
02-01-2011, 04:23 PM
thanks for the reply Kor-
How would i use your suggestion in my specific case?
To be clear- i want something that will basically override the browser back button's normal functionality (where 'normal' doesnt work 'normally' when an iframe is used anyway). I dont want to put a new back button on the page anywhere.

I'm not much of a js coder so you might need to spell it out for me- sorry in advance

Kor
02-01-2011, 05:46 PM
To be clear- i want something that will basically override the browser back button's normal functionality
I guess that is not possible. The browser's functionality is out of the client-side language's range.

darnen101
02-01-2011, 08:00 PM
well i might have mispoken-
I dont necessarily want to 'override' the back button, i just need a script that will load the iframe history states in a way that does not effect the history states of the main page.
If i go from page1 to page2, and then in page2 is an iframe that then loads iframe2, iframe3, iframe 4- hitting the back button would just take me back to iframe3 when i want it to go back to page1. Get what i mean?