/    Sign up×
Community /Pin to ProfileBookmark

History Object

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

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@havikMar 31.2003 — 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
Copy linkTweet thisAlerts:
@raghuauthorMar 31.2003 — 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.
Copy linkTweet thisAlerts:
@raghuauthorApr 01.2003 — 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>
Copy linkTweet thisAlerts:
@havikApr 01.2003 — 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
Copy linkTweet thisAlerts:
@PeterAceApr 01.2003 — 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
Copy linkTweet thisAlerts:
@havikApr 01.2003 — 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
×

Success!

Help @raghu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...