Connecting Tech Pros Worldwide Forums | Help | Site Map

history.back() in iframe

hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#1: Mar 7 '08
I have an iframe in which there is a link with href="javascript:history.back()"

But instead of moving the iframe's location back, it moves back the main page.

Any solution?

hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#2: Mar 8 '08

re: history.back() in iframe


Solved:

For an iframe, back link should be:[html]<a href = "javascript:parent.document.getElementById('id_Of_ Iframe').contentWindow.history.back();" >Back</a>[/html]
rnd me's Avatar
Expert
 
Join Date: Jun 2007
Location: Urbana IL
Posts: 411
#3: Mar 8 '08

re: history.back() in iframe


EDIT- solved while posting.

i cannot reproduce the problem in FF or ie7, is this an issue on either of those?

---------
general suggestions:
name your iframe and set the A's target attrib to the name.
try this.history.back()
use javascript:void(back()) in firefox, or something like window.back?back():history.back()

keep you own page history stack using push() and pop() to change location of frame.
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#4: Mar 8 '08

re: history.back() in iframe


Quote:

Originally Posted by rnd me

i cannot reproduce the problem in FF or ie7, is this an issue on either of those?

With Firefox.
Quote:

Originally Posted by rnd me

---------
general suggestions:
name your iframe and set the A's target attrib to the name.

This works good! I missed using target. I had in mind that target is by default the same frame in which the <a> is. Which is actually right, but somehow, history.back() is an exception.
Quote:

Originally Posted by rnd me

try this.history.back()
use javascript:void(back()) in firefox, or something like window.back?back():history.back()

keep you own page history stack using push() and pop() to change location of frame.

That is only good if you have to show a drop down when a user click on a custom back button inside the page. You can thus ask him to choose any of the previous pages. That can be used.

Thanks

Harpreet
Reply


Similar JavaScript / Ajax / DHTML bytes