Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allow use of back button on IFRAME

Status
Not open for further replies.

bfjacobs

Technical User
Sep 6, 2002
26
US
I have a site where I have 50 different pages go to an iframe. I have the following script in the page so that when a search engine finds the page that it will go to the original page and not just the page that is suppose to show up in the iframe.
<!--

if (top == self) {
top.location = &quot;churches.htm&quot;
}

//-->

The problem is (finally) that if someone finds the page on a search engine, they cannot use the browser back button to get to the search engine.

Does anyone have an idea on how to remedy this problem?

Thanks for your help
 
For due to fairly obvious security concerns the history object doesn't actually expose the urls that it contains (you don't necessarily want your company's intranet to know that you were visiting the playboy site). So we can't do the sensible thing and when running your script, grab the URL from 2 clicks ago and overwrite the most recent history URL.

In my (ever so humble) opinion, there are a couple of ways around this problem.

Firstly, you could simply add a link back to the search results
Code:
<a href=&quot;javascript:window.history.go(-2)&quot;>
.

Secondly, you can investigate the
Code:
document.referrer
property to see which page immediately preceded the page you are on, this will give you some idea of whether or not you need to provide an additional link.

Thirdly, and this is probably where you might want to go for an overall useability reason. Javascript redirect pages - although quick and easy - tend to bugger up the standard functionality of the user's browser. Why not reconfigure your search results such that they pass the actual URL to the IFRAME page as a parameter:
Code:
<a href=&quot;/iframepage.html?targetpage=/different.html&quot;>
That way you can use javascript to strip out the targetpage value and load it up in the IFRAME without causing the user's back button to lose it's functionality.

Hope I've given you something to chew over.
 
As far as the search engine thing, it is when someone uses Google etc. that causes the problem as I have no search engine on my site.

I used your first suggestion which works just fine, and I thank you for the help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top