Enable Back Button feature in an HTA

B

Bud Zielinski

Can someone point me to a script that will allow me to implement a
"back button" in an HTA, since there is no history for HTA's.

Understand this requires an array, is there any sample code out there
?

thanks

Bud
 
T

Thomas 'PointedEars' Lahn

Bud said:
Can someone point me to a script that will allow me to implement a
"back button" in an HTA, since there is no history for HTA's.

Understand this requires an array, is there any sample code out there
?

Do not write spaces before sentence marks as it confuses automagic
line-break as you see here.

You will need frames for this quickhack. Put it in the frame documents
(it is best to include the plain JavaScript part in a .js file and link
to it then):

function History(target)
{
var items = [];
var currentItem = 0;

this.goto =
function history_goto(sURL)
{
items[currentItem++] = target.location;
target.location = sURL;
};

this.go =
function history_go(n)
{
if (currentItem + n < 0 || currentItem + n > items.length - 1)
{
if (n < 0)
n = -currentItem;
else
n = items.length - 1 - currentItem;
}
target.location = items[currentItem += n];
};

this.back =
function history_back()
{
this.go(-1);
};

this.forward =
function history_forward()
{
this.go(+1);
};
}

/*
* The non-function properties of the prototype are accessible
* via the function properties, the methods, only. If you need
* direct access, declare them as properties of `this' instead.)
*/

if (parent)
{
if (!parent.history)
// Let the history be a property of the parent frameset;
// navigation affects the location of the current frame (window)
parent.history = new History(window);
}

function checkProp(sProp)
{
return (parent && parent.history && parent[sProp]);
}

function back()
{
if (checkProp("back"))
parent.history.back();

return false;
}

function forward()
{
if (checkProp("forward"))
parent.history.forward();

return false;
}

function goto(sURL)
{
if (checkProp("goto"))
parent.history.goto(sURL);

return false;
}

<a
href="#"
onclick="return back();">Back</a>
<a
href="#"
onclick="return forward();">Forward</a>
...
<a
href="foobar.html"
onclick="return goto(this.href);">Next</a>


HTH

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top