Solved

Problem with Accesskey in IE

Posted on 2002-04-09
18
268 Views
Last Modified: 2008-03-10
I am trying to make this piece of code to work on IE 5.x but it does not. I was to execute a piece of javascript when accelerator key Alt+P is pressed.
Any suggestions to make it work?

It apparently works very well with Netscape 6.2

<html>
<head>
</head>
<body>
<a accesskey="p"   href="javascript:alert('This is an alert')">
<img src="bin.jpg" name="left" border="0" alt="Click or 'ALT P' for previous page" WIDTH="30" HEIGHT="26"></a>
</body>
</html>

Nikhil
0
Comment
Question by:nikhilh
18 Comments
 
LVL 12

Expert Comment

by:lexxwern
ID: 6927761
I tried out the script you gave above; in IE6 too it did not work! what i observed was that whne i pressed Alt+P, the whole javascript command appeared in the Status Bar. Wierd working of MSIE.


lexxwern
0
 
LVL 14

Expert Comment

by:avner
ID: 6927791
Seems like a Bug.

This workaround seems to work :

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function pCheck()
{

if (event.keyCode!="80" || !event.altKey)    
     {
          return true;
     }
document.getElementById("aa").click();
}
//-->
</SCRIPT>
</head>
<body onkeydown="pCheck();">
<a id="aa"   href="javascript:alert('This is an alert')">
<img src="bin.jpg" name="left" border="0" alt="Click or 'ALT P' for previous page" WIDTH="30" HEIGHT="26"></a>

</body>
</html>
0
 
LVL 2

Author Comment

by:nikhilh
ID: 6927805
That will not work for a web site.. I will have to have a big switch statement to compare all the event keys that I want to trap. I was hoping that the accesskey function would save me that trouble.. except for this problem..

Thanks
0
 
LVL 14

Expert Comment

by:avner
ID: 6927819
ACCESSKEY does work in IE.
It seems like only with ALT+P there is a problem.

This workaround will cover this small bug, other ACCESSKEY can be used.
0
 
LVL 2

Author Comment

by:nikhilh
ID: 6927847
ALT+P was just a example.. I tried it for quite a few keys and it does not work.

0
 
LVL 14

Expert Comment

by:avner
ID: 6927854
This example seems to work :

<LABEL FOR="fp1" ACCESSKEY="P">#<SPAN style="text-decoration:underline;">P</SPAN>:
    Press Alt+P to set focus to textbox</LABEL>
<INPUT TYPE="text" NAME="T1" VALUE=text1 SIZE="20"
    TABINDEX="1" ID="fp1">


with P
0
 
LVL 2

Author Comment

by:nikhilh
ID: 6927857
ALT+P was just a example.. I tried it for quite a few keys and it does not work.

0
 
LVL 14

Expert Comment

by:avner
ID: 6927860
check out this url :

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtmlrefs.asp


What you need to try is :
<INPUT type="button"  ACCESSKEY="P" onclick="alert('moshe')">

It seems like the <A> tag does not fire the onclick and just sets the focus.

0
 
LVL 2

Author Comment

by:nikhilh
ID: 6927863
The problem is probably with invoking Javascript.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 14

Expert Comment

by:avner
ID: 6927866
It's not a problem.
It's the way ACCESSKEY behaves.
IT doesn't always invoke onclick event, on <A> tag it just set the focus (you can then call the method on the onfocus handler as a work around).
0
 
LVL 2

Author Comment

by:nikhilh
ID: 6927867
The problem is probably with invoking Javascript.
0
 
LVL 2

Author Comment

by:nikhilh
ID: 6927871
Netscape 6.2 supports it absolutely fine, so I thought that IE 5 should also have a support for the same.
0
 
LVL 14

Expert Comment

by:avner
ID: 6927878
But I don't understand the problem now.
0
 
LVL 2

Author Comment

by:nikhilh
ID: 6927879
Netscape 6.2 supports it absolutely fine, so I thought that IE 5 should also have a support for the same.
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8123487
This question has been abandoned. I will make a recommendation to the moderators on its resolution in a week or so. I appreciate any comments that would help me to make a recommendation.
 
In the absence of responses, I may recommend DELETE unless it is clear to me that it has value as a PAQ. Silence = you don't care
 
ahosang
0
 
LVL 2

Author Comment

by:nikhilh
ID: 8125259
None of the above comments worked. So as far as I am concerned, you can DELETE the same.
0
 
LVL 14

Accepted Solution

by:
avner earned 100 total points
ID: 8125464
nikhilh and ahosang  , I do not agree.

The question is regarding :
<a accesskey="p"   href="javascript:alert('This is an alert')">
to work on IE5.x
As I stated aboce the ALT + P for IE with A tags, fires an "onfocus" event, and not "onclick" event like NS6 does.

As I also stated, this is by design and not a bug and there for is the solution for your problem.

For a workaround, as I suggested above , use onchange event :
<a accesskey="p"   onfocus="javascript:alert('This is an alert')" href="void()">use onchange</a>


This question was fully answerd.
0
 

Expert Comment

by:SpideyMod
ID: 8303711
answered by avner

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now