Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a href return javascrpt value to link to anchor

Status
Not open for further replies.

bewin99

Programmer
Sep 25, 2008
15
GB
I have a custom piece of Javascript which softly scrolls the page down with a normal anchor link e.g.<a href="#Bottom"> which used to work fine until I got Javascript to listen out for a Java applet:

Code:
<script type="text/javascript" language="JavaScript">//<![CDATA[ 
function JumpToAnchor(anchorName) 
{ 
  SoftScroll.init(); 
  SoftScroll.go(anchorName); 
} 
//]]> 
</script>

The above will listen for an anchor call from a Java Applet with the following code bellow, that anchor being "Top":

Code:
void mousePressed() { 
    JSObject win = (JSObject) JSObject.getWindow(this); 
  String[] arguments = { "Top" }; 
  win.call("JumpToAnchor", arguments);
}


The problem is that the first button at the top of my page is a JPG image and uses just a normal anchor link <a href="#Bottom"> which works, the page goes down, but it does not activate the javascript which scrolls the page smoothly. However when at the bottom of the page and I click the Java Applet (which returns a call) the page scrolls up smoothly.
This leads me to believe that the Javascript takes precedence over the HTML anchor call and so I tried turning the a HREF into a JavaScript call like this:

Code:
<a href="#Bottom" OnClick="javascript:JumpToAnchor();"><img src="image.jpg"</a>


But I think the HTML takes one look at the beginning of this a href call and acts on it, thus the page does not flow, it jumps.

What do I do to get the page to scroll smoothly with an image anchor link?

the smooth scrolling javascript:
my page:
 
Try this:

Code:
<a href="#Bottom" onclick="JumpToAnchor('Bottom'); return(false);"><img src="image.jpg" /></a>

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Oh my friend, my very good friend, you did it. The final piece in the puzzle sorted!

Thank you, top marks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top