Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- JavaScript location = bookmark/id on same page?


Drag_Racer - 10:31 am on Apr 27, 2007 (gmt 0)


ok, I had errors...

I was half thinking a 'replace' on the regex... a little sleepy
and the onChange event won't fire until the input looses focus
you need to add the autocomplete=off to the form else you get an exception error for the autocomplete in FF.

I just tested this in IE5.5, OP6.06, FF1.5

now you can figure out how to grab the keystroke with out the input, cause you have to scroll back up the page to enter a new letter. adding focus back to the input kind of defeats the whole thing as the page scrolles back to it. you could have the input follow you around the page, maybe...

<script type="text/javascript">
function goTO(){
var myID = document.getElementById('myInput').value;
document.getElementById('myInput').value = '';
var fixurl;
if(window.location.hash){
fixurl = window.location.href.replace( /#.*$/,'')+'#'+myID;
}
else {
fixurl = window.location + "#" + myID;
}
window.location = fixurl;
}
</script>

<form autocomplete='off'><input id="myInput" onKeyUp="goTO()"></form>


<a name="a"><!-- --></a><h1>header a</h1>

<a name="b"><!-- --></a><h1>header b</h1>

<a name="c"><!-- --></a><h1>header a</h1>

<a name="d"><!-- --></a><h1>header b</h1>

<a name="e"><!-- --></a><h1>header a</h1>

<a name="f"><!-- --></a><h1>header b</h1>


Thread source:: http://www.webmasterworld.com/javascript/3320399.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com