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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

History.back()

Status
Not open for further replies.

ckleow

Programmer
Apr 17, 2001
6
0
0
MY
Dear all,

I am stuck at this problem. I've got 2 iframes open in one html page, one I shall call "IFrameTop" and the other one I shall call "IFrameBottom". I've also put "history.back()" in a link called BACK in IFrameBottom.

However, right after everytime I click on any link in IFrameTop(the focus is on IFrameTop), and I then click the BACK link in IFrameBottom, the link will make IFrameTop go back instead of IFrameBottom.

Can someone please help me. I am stuck here. I realize that this happens in IE 5.5 but not IE 5.0.

Thanks a lot for your help, people!
ckleow

Below is my code;
-----------------
<html>
<head>
<title>zoomFinance:Article Preview</title>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot;>
</head>
<script language=&quot;JavaScript&quot;>
self.name = &quot;this&quot;;
function goBack() {

history.back();

}
</script>

<%@ include file=&quot;../scripts/jscode.js&quot; %>

<table width=&quot;750&quot; height=&quot;100%&quot; cellspacing=&quot;3&quot; cellpadding=&quot;3&quot; bgcolor=&quot;#2B2B2B&quot;>
<tr>
<td colspan=&quot;4&quot;>
<div>
<table width=&quot;98%&quot; border=&quot;0&quot; align=&quot;center&quot; height=&quot;100%&quot;>
<tr>

-------------------------------
Below is the BACK link...
-------------------------------
<td>
<img border=&quot;0&quot; src=&quot;<%= IMAGE_BASE_URL %>icon_add.gif&quot;><font size=&quot;2&quot; face=&quot;Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;>
 <a href=&quot;JavaScript:goBack();&quot; class=&quot;headline&quot;>back</font></a>

------------------------------
</td>
</tr>

<tr>
<td>
<% if (strThumb[0].length() > 0) { %>
<img src=&quot;<%= strThumb[0] %>&quot; align=&quot;left&quot; valign=&quot;top&quot;>
<% } %>
<div>
<font size=&quot;2&quot; face=&quot;Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;><strong><%= strHeadline %></strong></font>
<font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;>
<!-- by <strong><a href=&quot;<%= toSource %>&quot; target=&quot;mnSrcInfo&quot; onClick=&quot;javascript: goInfoPage('mnSrcInfo','<%= toSource %>'); return false;&quot; class=&quot;headline&quot;><%= strDisplay %></a></strong>,-->
            
<%= formatBean.formatDate(dtCreated) %>
<hr size=&quot;1&quot;>
</font>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td colspan=&quot;4&quot;> <font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;>
</font>
<table width=&quot;98%&quot; border=&quot;0&quot; height=&quot;100%&quot; align=&quot;center&quot;>
<tr>
<td>
<font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;>
<%--
<% if (strSummary.length() > 1) { %>
<br>
<%= formatBean.formatText(strSummary) %><br>
<% } %>
--%>
<%= formatBean.formatContent(strContent, &quot;MN&quot;, strThumb, strImage, strCaption, &quot;&quot;) %>
</font>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
   <img border=&quot;0&quot; src=&quot;<%= IMAGE_BASE_URL %>icon_add.gif&quot;><font size=&quot;2&quot; face=&quot;Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;>
 <a href=&quot;JavaScript:goBack();&quot; class=&quot;headline&quot;>back</font></a>
</td>
</tr>
</table>
</body>
</html>
---------------
 
You need to refer to the frame that you want to go back in because each frame has it's own history. The easiest way to do this is pass a reference to the frame that you want to go back in to the goBack() function and then go back in it.

You can go back in multiple frames by sending multiple frame references to goBack() and going back as you loop through them.

Hope that helps.

/johnny
 
Hello Johnny!

Thanks a lot for helping me out...but how do you reference a particular frame? I tried a couple of ways but couldn't get it right. Below is my latest attempt, thank you very much for your help!

brgds,
ck

------------------

<%@ include file=&quot;../scripts/commonVars.jsp&quot; %>
<jsp:useBean id=&quot;mnBean&quot; class=&quot;i2Bean.mnBean&quot; scope=&quot;page&quot; />
<%

//
//Changes : MAX_IMAGES = MAX_IMAGES - 2
//Reason : the last 4 images are used for custom positioning in the RUM
//
int iLoop;
int iImages = 4;
boolean bPreview = false;
long lUpdater = 0;

String strMNID = request.getParameter(&quot;mnid&quot;);
String strUID = &quot;&quot;;
String strDisplay = &quot;&quot;;
String strUpdater = &quot;&quot;;
Date dtUpdated = null;
String strHeadline = &quot;&quot;;
String strSummary = &quot;&quot;;
String strContent = &quot;&quot;;
/////////////////////// changes ///////////////////////////
String strThumb[] = new String[mnBean.MAX_IMAGES - iImages];
String strImage[] = new String[mnBean.MAX_IMAGES - iImages];
String strCaption[] = new String[mnBean.MAX_IMAGES - iImages];
///////////////////////////////////////////////////////////
String strSrcImg = &quot;&quot;;
String strDeleted = &quot;&quot;;
String toSource = &quot;&quot;;

Date dtCreated = null;

strTemp = request.getParameter(&quot;options&quot;);
if (strTemp != null) {
if (strTemp.compareToIgnoreCase(&quot;previewmode&quot;) == 0) { bPreview = true; }
}

/////////////////////////// changes ///////////////////////
for (iLoop = 0; iLoop < mnBean.MAX_IMAGES-iImages; iLoop++) {
///////////////////////////////////////////////////////////
strThumb[iLoop] = &quot;&quot;;
strImage[iLoop] = &quot;&quot;;
strCaption[iLoop] = &quot;&quot;;
}

if (strMNID == null) { strMNID = &quot;&quot;; }

if (!mnBean.getArticle(strMNID)) {
System.err.println (&quot;getArticle: &quot; + mnBean.getError() + &quot; [&quot; + mnBean.getErrorCode() + &quot;]&quot;);
}

strUID = mnBean.getAuthor();
strDisplay = mnBean.getDisplay();
dtCreated = mnBean.getCreated();
strHeadline = mnBean.getHeadline();
strSummary = mnBean.getSummary();
strContent = mnBean.getContent();
strSrcImg = mnBean.getImage();
if (strDisplay.length() == 0) { strDisplay = strUID; }

//////////////////////// changes ///////////////////////////
for (iLoop = 0; iLoop < mnBean.MAX_IMAGES-iImages; iLoop++) {
////////////////////////////////////////////////////////////
strThumb[iLoop] = mnBean.getThumbC(iLoop);
if (strThumb[iLoop].length() > 0) {
strThumb[iLoop] = IMAGE_BASE_URL + &quot;MN/&quot; + strUID + &quot;/&quot; + strMNID + &quot;/&quot; + strThumb[iLoop];
}

strImage[iLoop] = mnBean.getImageC(iLoop);
if (strImage[iLoop].length() > 0) {
strImage[iLoop] = IMAGE_BASE_URL + &quot;MN/&quot; + strUID + &quot;/&quot; + strMNID + &quot;/&quot; + strImage[iLoop];
}
strCaption[iLoop] = mnBean.getCaptionC(iLoop);
}

if (strSrcImg.length() > 0) {
if (strUID.toLowerCase().indexOf(&quot;afa&quot;) > -1)
strSrcImg = IMAGE_BASE_URL + &quot;MN/&quot; + strUID + &quot;/&quot; + &quot;title_afx.gif&quot;;
else
if (strUID.toLowerCase().indexOf(&quot;bernama&quot;) > -1)
strSrcImg = IMAGE_BASE_URL + &quot;MN/&quot; + strUID + &quot;/&quot; + &quot;title_bernama.gif&quot;;
else
strSrcImg = IMAGE_BASE_URL + &quot;MN/&quot; + strUID + &quot;/&quot; + strSrcImg;
}

toSource = MN_SOURCE_INFO + &quot;?uid=&quot; + strUID;

if (bPreview) {
%>

<html>
<head>
<META HTTP-EQUIV='EXPIRES' CONTENT='0'>
<META HTTP-EQUIV='PRAGMA' CONTENT='NO-CACHE'>
<META Name = &quot;Copyright&quot; content=&quot;Copyright© 2000 Forum Digital Sdn Bhd&quot;>
<META Name = &quot;Keywords&quot; content=&quot;real-time quotes, realtime quotes, quotes, finance, financial, malaysia, content, financial news, financial content&quot;>
<title>zoomFinance:Article Preview</title>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot;>
</head>
<body>
<%
}
%>

<html>
<head>
<title>zoomFinance:Article Preview</title>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot;>
</head>
<script language=&quot;JavaScript&quot;>
self.name = &quot;this&quot;;
function goBack() {
***my failed attempt to reference IFrameBottom***
parent.iframesResult.history.go(-1);

**************************************************
}
</script>

<table width=&quot;750&quot; height=&quot;100%&quot; cellspacing=&quot;3&quot; cellpadding=&quot;3&quot; bgcolor=&quot;#2B2B2B&quot;>
<tr>
<td colspan=&quot;4&quot;>
<div>
<table width=&quot;98%&quot; border=&quot;0&quot; align=&quot;center&quot; height=&quot;100%&quot;>
<tr>
<td>
<img border=&quot;0&quot; src=&quot;<%= IMAGE_BASE_URL %>icon_add.gif&quot;><font size=&quot;2&quot; face=&quot;Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;>
 <a href=&quot;JavaScript:goBack();&quot; class=&quot;headline&quot;>back</font></a>
</td>
</tr>

<tr>
<td>
<% if (strThumb[0].length() > 0) { %>
<img src=&quot;<%= strThumb[0] %>&quot; align=&quot;left&quot; valign=&quot;top&quot;>
<% } %>
<div>
<font size=&quot;2&quot; face=&quot;Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;><strong><%= strHeadline %></strong></font>
<font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;>
<!-- by <strong><a href=&quot;<%= toSource %>&quot; target=&quot;mnSrcInfo&quot; onClick=&quot;javascript: goInfoPage('mnSrcInfo','<%= toSource %>'); return false;&quot; class=&quot;headline&quot;><%= strDisplay %></a></strong>,-->
            
<%= formatBean.formatDate(dtCreated) %>
<hr size=&quot;1&quot;>
</font>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td colspan=&quot;4&quot;> <font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;>
</font>
<table width=&quot;98%&quot; border=&quot;0&quot; height=&quot;100%&quot; align=&quot;center&quot;>
<tr>
<td>
<font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;>
<%--
<% if (strSummary.length() > 1) { %>
<br>
<%= formatBean.formatText(strSummary) %><br>
<% } %>
--%>
<%= formatBean.formatContent(strContent, &quot;MN&quot;, strThumb, strImage, strCaption, &quot;&quot;) %>
</font>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
   <img border=&quot;0&quot; src=&quot;<%= IMAGE_BASE_URL %>icon_add.gif&quot;><font size=&quot;2&quot; face=&quot;Arial, Helvatica, sans-serif&quot; color=&quot;#FFFFFF&quot;>
 <a href=&quot;JavaScript:goBack();&quot; class=&quot;headline&quot;>back</font></a>
</td>
</tr>
</table>
</body>
</html>
 
OK, i have 2 pages, one is a search console, the other is a javascript new window which opens when user presses search. we want to have a back button on the results page that returns the user back to the search console which is still open without reloading it every time. i know this can be done but need some help with the code if any one can help, or point me to a site using something similar. thanks in advance
 
I am sort of working on the same thing. I have a top frame and bottom frame. I want the user to click on my back history botton on the top window and reference the history in the bottom frame to take the user to the previous bottom frame. How do I do this?
 
indigojo:

Are you sure you want your button to imply that the user is going back? It should, in human interface design terms, suggest that they are going to return to the search window. The way to do this is:

var search_win = window.open(url,name,attributes);
Here you are setting the window to a variable (search_win) so you can reference it later.

then for your &quot;back&quot; button:

<a href=&quot;javascript:search_win.focus();&quot;><img src=&quot;your_button.gif&quot;></a>

All this does is bring the search_win window to the front and does not reload it.
 
hoffa2:

To go back in the bottom frame from a link in the top frame:

<a href=&quot;javascript:top.frames[1].history.back();&quot;>Back</a>

where frames[1] is the second frame the the frames array. You could also use the_name_of instead of frames[1].

Hope this helps,
/johnny
 
I used:

<a href=&quot;javascript:top.frames[1].history.back();&quot;>Back</a>

in a top frame to go back one page in the bottom frame. It works fine with Netscape 4.6 but does not work with Internet Explorer. I've tried several other methods of accomplishing the same thing and none of them would work in Internet Explorer.

Can anyone tell me how to do this so that it will work in IE?

Thanks

Tom Esker
tjesker@interdyne.com
 
I had the same problem...here is soome code that worked for me:

<a href=&quot;#&quot; onClick=&quot;top.history.back()&quot;>Back</a>
 
Actually in my site i would like to avoid clients to go to back what is the code to be used for that

actually i know that by setting the value of history.back() to -1 we can avoid it but how to use it i proper way i feeling difficult

pls help me out with this

regards
 
script Doubts>> a cheeky way around this would be to use the javascript location.replace(url) when you click a link (this loads the linked document OVER the current doc in the document history list) . . . you could use event capture to get the clicked link's href value and then use a location.replace(URL) to load it. . . . any use? If you want this in more detail, let me know . . . :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top