Forum Moderators: open

Message Too Old, No Replies

Using named anchors in a scrollable div

How can I make this work?

         

runner

8:13 pm on Dec 10, 2004 (gmt 0)

10+ Year Member



I have several web pages that contain a div with a navigation menu and a div with a scrollable area. I want to be able to click on a link in the nav menu and have the scrollable area jump to the indicated named anchor.

Can this be done and does anyone have a link to an example of this?

tedster

8:25 pm on Dec 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tried to get this kind of set-up working for a site template I created last year - I had no luck using divs, it had to be an iframe for named anchors to work as I intended.

But iframes were not a viable option for that website, so what I did was use some dHTML - the links trigger a show/hide divs function - and I put each "linked to" section of the content in its own <div></div> element.

Further scripting was then needed, because visitors from search engines would not immediately see their search words on screen. But with a few hours of scripting it all worked out. In fact, there's been a lot of positive feedback from users about how easy the pages are to work with.

iamlost

8:26 pm on Dec 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes.

Read the w3c specs for "how-to" examples:
[w3.org ]

Actually look at that pages source code - they do much like you are asking.

runner

11:29 pm on Dec 13, 2004 (gmt 0)

10+ Year Member



I got it working using an iframe

kk5st

6:29 am on Dec 14, 2004 (gmt 0)

10+ Year Member



Hi Runner,

Unless I misunderstand the requirements, this should do just fine;


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator"
content="HTML Tidy for Linux/x86 (vers 1st March 2002), see www.w3.org" />
<meta name="editor" content="Emacs 21" />
<meta name="author" content="Gary Turner" />
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-1" />

<title>Jump into scrollable div</title>

<style type="text/css">
/*<![CDATA[*/

html, body {
margin: 0;
padding: 0;
}

p {
margin-top: 0;
}

#holderdiv {
width: 150px;
height: 75px;
overflow: auto;
border: 1px solid black;
}

/*]]>*/
</style>
</head>

<body>
<p><a href="#top">top</a><br />
<a href="#here">here</a><br />
<a href="#there">there</a><br />
<a href="#everywhere">everywhere</a></p>

<div id="holderdiv">
<p id="top">top<br />
filler<br />
filler<br />
filler</p>

<p id="here">here<br />

filler<br />
filler<br />
filler</p>

<p id="there">there<br />
filler<br />
filler<br />

filler</p>

<p id="everywhere">everywhere<br />
filler<br />
filler<br />
filler</p>
</div>

</body>
</html>


Iframes violate the KISS principal :) and have accessibility issues.

cheers,

gary

runner

9:14 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



WOW! It works! Thanks Gary.

Now I have to redesign everything. At least I'm learning something.

So, as a general rule, I will stay away from frames and iframes.

iamlost

10:10 pm on Dec 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Because of tedsters comment above I have been running some tests.

Unfortunately the above example and all variations I have tried so far break in Opera.

Fine in IE 5.0/5.5/6.0, fine in Netscape 7.*, fine in Firefox from 0.7 (at least) on. But not in Opera 7.x.

runner

10:20 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



I think what I may do is look at my web server stats and get a listing of the visitor's browser types. If there aren't any opera users I may move forward.

runner

11:44 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



I do have some opera browsers visiting the site.

Even Netscape 4.79 and IE 5.5

kk5st

12:04 am on Dec 15, 2004 (gmt 0)

10+ Year Member



Unfortunately the above example and all variations I have tried so far break in Opera.
After seeing the comment, I said to myself, "self, maybe iamlost didn't try an anchor+name". Well, he probably did, and no, it doesn't work either.

I'm getting just a bit fed up with Opera. There was a time when I thought it was a pretty good browser (Opera5?). I just keep running into more and more non-conformance and just weirdly buggy behavior.

The trouble is, Opera's behavior could arguably be a correct one. In my example, if you shorten the browser window so that only the links are seen, clicking one will shift the div up to top of viewport if the named element, hidden or not, is below the window. If the named element were scrolled out of the div to the top, and it would be in the viewport were it not hidden, it will not shift.

Ah well, cheers,

gary

tedster

3:31 am on Dec 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Opera support may not be important - but I'll bet Macinstosh support is, at least for IE5 and Safari. Those two browsers are worth testing before you commit, I'd say.