If the user enters a new url, the current url is stored in an array/stack. When the user presses back, the item is popped off the stack and displayed in the current url, and the current url goes into a new url allowing the user to click forward through the web pages.
However, when the backStack array is empty I don't want the user to be able to click back any more, and vise versa for the forStack array. Any idea how I can do this?
<HTML>
<HEAD>
<TITLE>Stacking up!</TITLE>
<script>
var backStack = new Array();
var forStack = new Array();
var curUrl = "";
function pushStack(newVal) {
if (curUrl == "")
curUrl = newVal;
else
backStack.push(curUrl);
curUrl = newVal;
}
function pushForStack(newVal) {
forStack.push(curUrl);
curUrl = newVal;
}
function popBackStack() {
var popVal = backStack.pop();
if (popVal == undefined)
return "Nothing left!";
else
return popVal
}
function popForStack() {
var popVal = forStack.pop();
if (popVal == undefined)
return "Enter a new URL";
else
return popVal;
}
function showStack(theSelect){
theSelect.options.length = 0;
for (var i = 0; i < backStack.length; i++){
var theOption = new Option(backStack[i]);
theSelect.options[theSelect.options.length] = theOption;
}
}
function showStack2(theSelect){
theSelect.options.length = 0;
for (var i = 0; i < forStack.length; i++){
var theOption = new Option(forStack[i]);
theSelect.options[theSelect.options.length] = theOption;
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<table width="104%" height="364" border="5" cellpadding="3" cellspacing="3">
<tr>
<th width="30%" height="78" scope="col"><p>
<INPUT type=button value="Back" onclick='txtPop.value = popBackStack(); pushForStack(txtPop.value); showStack(theList); showStack2(theList2);'></p></th>
<th width="46%" scope="col"><p>
<center>
<INPUT type=text name="txtPush">
<INPUT type=button value="Push" onclick='forStack.length=0; showStack2(theList2);pushStack(txtPush.value);txtPush.value="";txtPop.value = curUrl; showStack(theList);'>
</center>
</p></th>
<th width="24%" scope="col"><p><INPUT type=button value="Forward" onclick='txtPop.value = popForStack(); pushStack(txtPop.value); showStack(theList); showStack2(theList2);'></p></th>
</tr>
<tr>
<td><p><center>
<SELECT name="theList" size=12>
</SELECT>
</center></p></td>
<td><p><center><INPUT type=textki name="txtPop" id="txtPop" size=25></center></p></td>
<td><center>
<SELECT name="theList2" size=12>
</SELECT>
</center></td>
</tr>
</table>
</FORM>
<p> </p>
</BODY>
</HTML>

New Topic/Question
Reply


MultiQuote




|