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


JAB_Creations - 8:42 pm on Apr 24, 2007 (gmt 0)


Nothing is more obnoxious then realizing that you've been using bad references!

This works, code might be a tad messy but it works! It gets a bit glitchy when there is already a fragment identifier in the URL so I've got to figure out how to avoid having my prompts add the pound to the URL when clicked, interesting challenges!

- John

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Power Keys</title>
<script type="text/javascript">

document.onkeypress = function(e) {
if (!e) { // for IE
e = event;
if (e.srcElement.id=="query_string") return;
e.which = e.keyCode;
} else { // for Fx
if (e.target.id=="query_string") return;
}
switch (e.which) {
case 83: // cap S
case 115: // lower s
document.getElementById("query_string").focus();
}
var id1 = "#content";
switch (e.which) {
case 99: // lower s
{location.href = location + id1;}
}
}
</script>
<style type="text/css">#query_string:focus {background: #abc;}</style>
</head>

<body>

<p>Press F2 to give focus to search text field, use keycode 83 to assign to letter S though it will not work?</p>

<form>
<fieldset>
<label for="query_string">Search Site</label><input id="query_string" type="text" value="Search this site..." /><input type="submit" value="Search" />
</fieldset>
</form>

<div id="content" style="margin-top: 600px;">Content</div>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />

</body>
</html>


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