Elegant way to focus back in the middle of my page?

D

DualFlex

Hi all,

I have this long vertical list of links refering to different web
pages (actually Adobe captivate screen cast).

When my user is done with my tutorial he clicks on a "back" button.

Coming back, I use the "window.location" feature but would like to
land say in the middle of my page , actually at the level of the
cliked hyperlink (not always at the top of the page).

I am starting with JS... Not a DOM guru yet!

Any way of not using anchors on my first page?

Any piece of code would be appreciated.

Thanks for reading!
Dualflex
p.s.: the context is also mediawiki, hope I can mix wikitext with JS...
 
T

Trevor Lawrence

DualFlex,

My original thought was to use anchors on the first page e.g.
<a name= "link1">
<a name= "link2">
etc.

Are you saying that you don't want to use these? I don't see how you can
avoid doing so.

If you are willing to proceed using named anchors, the problem arises as to
how the called page knows where to go back to, i.e to which anchor. Here I
can only suggest using a query string, e.g from the first page use
<a name="link1" href="page1.html?xxx=link1">Page 1</a>
etc.

In page1.html you would need to extract the anchor name and use it in the go
back link. This function will do so:
function qsobj(parm) {
// get url string after '?' and split by "&" into an array
var qpairs = location.search.substring(1).split("&");
if (!qpairs) { return null; }

// split qpairs[parm] by "=" into an array
var qvbl = qpairs[parm].split("=");

// return result if it exists, else blank string
return qvbl[1] ? unescape(qvbl[1].replace(/%20|\ +/g," ")) : '';
} // ---- end qsobj() ------------

So the link in page1.html back to index.html would be (not tested):
<a href = "#" onclick="window.location='index.html#' + qsobj(1);">Go Back
</a>
 
D

David Mark

Working!

This is really elegant! Used the following:

 window.history.back();

Great. You just created a second back button. Not a good idea to add
redundant interfaces to confuse the user.

[snip]
 
D

David Mark

Should I disable three of the four mechanisms that open the boot (trunk)
of my car, in order to comply with this rule?

I don't know what opens your car or who designed it, but if you can
touch more than one of those at a time, there is a redundancy issue.
Call your dealer for more information.
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top