LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-06-2008, 03:33 AM   #1
secretlydead
Member
 
Registered: Sep 2003
Location: Qingdao, China
Distribution: mandriva, slack, red flag
Posts: 249

Rep: Reputation: 31
html - body onload not in a form


I have a web page that loads up. I want the a link to be highlighted within it, so if the user hits 'enter', it follows the link.

the link is like
<a href='page.php' id='xx'>Go here.</a>


is it possible to do this with body onload?

this doesn't work:
<body onload="document.getElementById('xx').focus()">
 
Old 09-06-2008, 10:55 AM   #2
secretlydead
Member
 
Registered: Sep 2003
Location: Qingdao, China
Distribution: mandriva, slack, red flag
Posts: 249

Original Poster
Rep: Reputation: 31
I haven't figured out that, but this works:

<script language="JavaScript1.2">
<!--
/*
script written by JavaScript Kit (www.javascriptkit.com)
More free scripts here
*/
if (document.layers)
document.captureEvents(Event.KEYPRESS)
function backhome(e){
var targeturl="http://www.javascriptkit.com"
if (document.layers||document.getElementById&&!document.all){
if (e.which==104||e.which==72)
window.location=targeturl
}
else if (document.all){
if (event.keyCode==104||event.keyCode==72)
window.location=targeturl
}
}
document.onkeypress=backhome
//-->
</script>


and this resource is very useful when working with the script above:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2"><!--
function netscapeKeyPress(e) {
if (e.modifiers == 2) {
// a - Select all
// b - Edit bookmarks
// c - Copy
// d - Add bookmark
if (e.which == 5 ) alert('Ctrl and e pressed');
// f - Find in page
// g - Find Again
// h - Open History
// i - Page Info
if (e.which == 10) alert('Ctrl and j pressed');
if (e.which == 11) alert('Ctrl and k pressed');
if (e.which == 12) alert('Ctrl and l pressed');
// m - New Message
// n - New Navigator Window
// o - Open Page
// p - Print
// q - Exit
// r - Reload
// s - Save As
if (e.which == 20) alert('Ctrl and t pressed');
// u - Page source
// v - Paste
// w - Close
// x - Cut
if (e.which == 25) alert('Ctrl and y pressed');
// ?
}
else if (e.modifiers == 4) {
if (e.which == 65) alert('Shift and A pressed');
if (e.which == 66) alert('Shift and B pressed');
if (e.which == 67) alert('Shift and C pressed');
if (e.which == 68) alert('Shift and D pressed');
if (e.which == 69) alert('Shift and E pressed');
if (e.which == 70) alert('Shift and F pressed');
if (e.which == 71) alert('Shift and G pressed');
if (e.which == 72) alert('Shift and H pressed');
if (e.which == 73) alert('Shift and I pressed');
if (e.which == 74) alert('Shift and J pressed');
if (e.which == 75) alert('Shift and K pressed');
if (e.which == 76) alert('Shift and L pressed');
if (e.which == 77) alert('Shift and M pressed');
if (e.which == 78) alert('Shift and N pressed');
if (e.which == 79) alert('Shift and O pressed');
if (e.which == 80) alert('Shift and P pressed');
if (e.which == 81) alert('Shift and Q pressed');
if (e.which == 82) alert('Shift and R pressed');
if (e.which == 83) alert('Shift and S pressed');
if (e.which == 84) alert('Shift and T pressed');
if (e.which == 85) alert('Shift and U pressed');
if (e.which == 86) alert('Shift and V pressed');
if (e.which == 87) alert('Shift and W pressed');
if (e.which == 88) alert('Shift and X pressed');
if (e.which == 89) alert('Shift and Y pressed');
if (e.which == 90) alert('Shift and Z pressed');
}
}

function microsoftKeyPress() {
if (window.event.ctrlKey) {
// a - Select All
// b -Organise Favourites
// c - Copy
// d -Add to Favourites
if (window.event.keyCode == 5 ) alert('Ctrl and e pressed');
// f -Find (on this page)
if (window.event.keyCode == 7 ) alert('Ctrl and g pressed');
if (window.event.keyCode == 8 ) alert('Ctrl and h pressed');
if (window.event.keyCode == 9 ) alert('Ctrl and i pressed');
if (window.event.keyCode == 10) alert('Ctrl and j pressed');
if (window.event.keyCode == 11) alert('Ctrl and k pressed');
// l - Open
if (window.event.keyCode == 13) alert('Ctrl and m pressed');
// n - New Window
// o - Open
// p - Print
if (window.event.keyCode == 17) alert('Ctrl and q pressed');
// r - Reload
// s - Save
if (window.event.keyCode == 20) alert('Ctrl and t pressed');
if (window.event.keyCode == 21) alert('Ctrl and u pressed');
// v - Paste
// w - Close
// x -Cut
if (window.event.keyCode == 25) alert('Ctrl and y pressed');
if (window.event.keyCode == 26) alert('Ctrl and z pressed');
}
else if (window.event.shiftKey) {
if (window.event.keyCode == 65) alert('Shift and A pressed');
if (window.event.keyCode == 66) alert('Shift and B pressed');
if (window.event.keyCode == 67) alert('Shift and C pressed');
if (window.event.keyCode == 68) alert('Shift and D pressed');
if (window.event.keyCode == 69) alert('Shift and E pressed');
if (window.event.keyCode == 70) alert('Shift and F pressed');
if (window.event.keyCode == 71) alert('Shift and G pressed');
if (window.event.keyCode == 72) alert('Shift and H pressed');
if (window.event.keyCode == 73) alert('Shift and I pressed');
if (window.event.keyCode == 74) alert('Shift and J pressed');
if (window.event.keyCode == 75) alert('Shift and K pressed');
if (window.event.keyCode == 76) alert('Shift and L pressed');
if (window.event.keyCode == 77) alert('Shift and M pressed');
if (window.event.keyCode == 78) alert('Shift and N pressed');
if (window.event.keyCode == 79) alert('Shift and O pressed');
if (window.event.keyCode == 80) alert('Shift and P pressed');
if (window.event.keyCode == 81) alert('Shift and Q pressed');
if (window.event.keyCode == 82) alert('Shift and R pressed');
if (window.event.keyCode == 83) alert('Shift and S pressed');
if (window.event.keyCode == 84) alert('Shift and T pressed');
if (window.event.keyCode == 85) alert('Shift and U pressed');
if (window.event.keyCode == 86) alert('Shift and V pressed');
if (window.event.keyCode == 87) alert('Shift and W pressed');
if (window.event.keyCode == 88) alert('Shift and X pressed');
if (window.event.keyCode == 89) alert('Shift and Y pressed');
if (window.event.keyCode == 90) alert('Shift and Z pressed');
}
}

if (navigator.appName == 'Netscape') {
window.captureEvents(Event.KEYPRESS);
window.onKeyPress = netscapeKeyPress;
}
//--></SCRIPT>

</HEAD>

<BODY onKeyPress="microsoftKeyPress()">

<h2>Key Pressing</h2>

Use some shift and control keys.

</BODY>
</HTML>
 
Old 09-06-2008, 01:45 PM   #3
secretlydead
Member
 
Registered: Sep 2003
Location: Qingdao, China
Distribution: mandriva, slack, red flag
Posts: 249

Original Poster
Rep: Reputation: 31
if you're interested in this, put this into a php file, then type shift-Y shift-N and shift-O and see what it does:


<?php
echo "hey.<br>";
?>

<script language="JavaScript1.2">
if (document.layers)
document.captureEvents(Event.KEYPRESS)
function Y(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==89)
window.location="testhotkeys.php?ziji=Y"
if (e.which==78)
window.location="testhotkeys.php?ziji=N"
if (e.which==79)
alert('Oh, Baby!')
}
}
document.onkeypress=Y
</script>

Last edited by secretlydead; 09-06-2008 at 02:31 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed command extract contents withing body tag of html Fond_of_Opensource Linux - Newbie 6 06-04-2007 07:55 AM
html question: form henrikanttonen Programming 4 08-13-2004 07:28 AM
Contact form on HTML Gerardoj Linux - General 1 03-26-2004 02:08 AM
an html form question matt_w_lambert Programming 3 10-30-2003 11:41 PM
problem with html form meluser Linux - Software 4 03-15-2003 12:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration