Click to See Complete Forum and Search --> : History Object


raghu
03-31-2003, 03:55 PM
Hi,

I have html page which opens a new window without tool bar and address bar.I have my own go back and go forward links.

If the user is at the first page the the go back link should be disabled and if the user is at the last page then the go forward link should be disabled.

is there a way I can do this using window.history.back and window.history.forward and disable when the first page/last page is reached


Regards,
Sachin

havik
03-31-2003, 03:57 PM
You need to reference your first and last pages and do a check for them everytime a new page is loaded. This way, if one of them is detected, the appropriate button can be disabled.

Havik

raghu
03-31-2003, 04:00 PM
I don't know both the first and last page,since these
are dependent on user actions.

Is there a way were in history object can be used to determine this.

raghu
03-31-2003, 08:06 PM
Hi,

I have a requirement where in i need to open a help file
in a small window which with my own go back and go forward buttons.
I need to disable the go back link if it is the first id in the file.
and enable otherwise. Similarly i also need to disable the forward link if it is the last page.

I don't know the first and the last page since, it is a single
help file something like.
help.htm#12
help.htm#13
help.htm#14

here is the sample code.

<html>
<head>
<script type="text/javascript">
function jsGoBack()
{
if (window.history.length != 0)
{
window.history.back()
}

}
</script>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td colspan="5" height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td width="4"></td>

<td width="4"></td>
<td height="58">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%" ID="Table2">
<tr>
<td valign="middle" align="right" bgcolor="#336699">
</td>
<td valign="middle" align="right" bgcolor="#336699">

<td width="2" bgcolor="#336699"></td>
</tr>
<tr>
<td colspan="2" height="1" bgcolor="#99ccff"></td>
</tr>
<tr>
<td colspan="2" valign="middle" width="100%" bgcolor="#e7e7e7">
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="left">
<tr>
<td width="15%" align="left" class="color003366">&raquo;&nbsp;<a href="javascript:jsGoBack();">Go
back </a>
</td>
<td width="20%" align="left" class="color003366">&raquo;&nbsp;<a href="javascript:window.history.forward();">
Go Forward</a></td>
<td width="15%" align="left" class="color003366">&raquo;&nbsp;<a href="helpsearchbar.htm" target="fmContent">
Search</a></td>
<td width="15%" align="left" class="color003366">&raquo;&nbsp;<a href="help.htm">All
topics</a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="5" height="1" bgcolor="#cccccc"></td>
</tr>
</table>
</body>
</html>

havik
04-01-2003, 09:20 AM
That jsGoBack() function doesn't work to disable the back button? Also, do the back and forward buttons act exactly like a browsers? Or are they used to navigate the help?

Havik

PeterAce
04-01-2003, 09:30 AM
I have exactly the same question. The history.length property show the number of entries in the "Go" menu, not the amount of pages you can go back to. Hence, it works the first time you come to this page, but after going to another page and back the back button is disabled, but the Go menu actually shows two pages. Therfore, the check with history.length does not work.

Is there a way to check whether the back button is disabled (even when the go menu shows multiple items)?

thanks,

Peter

havik
04-01-2003, 09:48 AM
Okay, I only see sample code here. Nothing I can get too deep into. But here's how I would approach the problem. I would set up a way to reference the pages. Lets say an array.

var pages = new Array();
pages[0] = 'help.htm#1';
pages[1] = 'help.htm#2';
etc...

Then I'll have an index variable set to 0. When the new window opens, pages[index] is loaded first. In this case, index is 0 but it could be something else. Then, whenever a forward is made, you could increment index and load the page at pages[index].

To disable the forward, do a check to see if the index variable is greater than or equal to pages.length.

Same with the back button, decrement index and load pages[index]. Disable back button when index is less than or equal to 0.

Example of how to load a URL from an array to the window.open function:

var array = new Array();
array[0] = "http://www.yahoo.com";

window.open(array[0], '', '');

Havik