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


Drag_Racer - 8:47 am on Apr 27, 2007 (gmt 0)


instead of worrying about the hash, you could use it instead of a search param (query string)

var myID = false;
if(window.location.hash && window.location.hash!= "#"){
myID = window.loacation.hash.substring(1,window.location.hash.length);
}

now 'myID' contains everything after the '#' in your url if you need it

... or just rewrite your window.location with a new hash upon keystroke as below

<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><input id="myInput" onChange="goTO()"></form>

maybe I'm just missing something your trying to do, but the above should navigate around a page. Even if the page does refresh, the hash will still make the uri good to your destination...


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