return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - prevent default 'F1' event in iE11 - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - prevent default 'F1' event in iE11 - Stack Overflow

programmeradmin1浏览0评论

When the user press F1 key,I am planning to display our application help and suppress default action. I tried with different options not to show help popup of IE. Here is my Code:

document.addEventListener('keydown', function (e) {
            if (e.key === 'F1' || e.keyCode == 112) {

                   e.cancelBubble = true;
                    e.cancelable = true;
                    e.stopPropagation();
                    e.preventDefault();
                    e.returnValue = false;

                //my help menu code goes here
            }
});

Please let me know how can i achieve in showing the help page of my application instead of IE help. I am using IE11 version.

When the user press F1 key,I am planning to display our application help and suppress default action. I tried with different options not to show help popup of IE. Here is my Code:

document.addEventListener('keydown', function (e) {
            if (e.key === 'F1' || e.keyCode == 112) {

                   e.cancelBubble = true;
                    e.cancelable = true;
                    e.stopPropagation();
                    e.preventDefault();
                    e.returnValue = false;

                //my help menu code goes here
            }
});

Please let me know how can i achieve in showing the help page of my application instead of IE help. I am using IE11 version.

Share Improve this question edited Jul 27, 2017 at 7:19 Tomasz Jakub Rup 10.7k7 gold badges51 silver badges49 bronze badges asked Mar 26, 2015 at 12:39 AMDIAMDI 9732 gold badges17 silver badges47 bronze badges 3
  • Have you tried event.originalEvent.keyCode = 0;, According to this answer it works in IE8 – CodingIntrigue Commented Mar 26, 2015 at 12:44
  • 1 I am not able to see event.originalEvent – AMDI Commented Mar 30, 2015 at 9:08
  • IE11: event.originalEvent => undefined – Pete Alvin Commented Jul 8, 2016 at 15:04
Add a ment  | 

3 Answers 3

Reset to default 6

You could subscribe to the window.onhelp event:

window.onhelp =function() { 
    alert();
    return false;
}

Try doing this

<script>
        $(document).ready(function () {

            removedefaulthelp();
            function removedefaulthelp()
            {
                window.onhelp = function () {
                    return false;
                    alert();
                }
            }
            document.addEventListener('keydown', function (e) {
                if (e.key === 'F1' || e.keyCode == 112) {
                    removedefaulthelp();
                    e.cancelBubble = true;
                    e.cancelable = true;
                    e.stopPropagation();
                    e.preventDefault();
                    e.returnValue = false;
                    //my help menu code goes here
                }
            });
}
</script>

Refer this for more information.

Here is an example similar to Sukanya's answer, but my solution shows how to extend for the F2-F12 keys, and purposely disregards F-bination keys, such a CTRL + F1.

<html>
<head>
<!-- Note:  reference your own JQuery library here -->
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
</head>
<body>
    <h1>F-key trap example</h1>
    <div><h2>Example:  Press the 'F1' key to open help</h2></div>
    <script type="text/javascript">
        //unment to prevent on startup
        //removeDefaultFunction();          
        /** Prevents the default function such as the help pop-up **/
        function removeDefaultFunction()
        {
            window.onhelp = function () { return false; }
        }
        /** use keydown event and trap only the F-key, 
            but not binations with SHIFT/CTRL/ALT **/
        $(window).bind('keydown', function(e) {
            //This is the F1 key code, but NOT with SHIFT/CTRL/ALT
            var keyCode = e.keyCode || e.which;
            if((keyCode == 112 || e.key == 'F1') && 
                    !(event.altKey ||event.ctrlKey || event.shiftKey || event.metaKey))
             {
                // prevent code starts here:
                removeDefaultFunction();
                e.cancelable = true;
                e.stopPropagation();
                e.preventDefault();
                e.returnValue = false;
                // Open help window here instead of alert
                alert('F1 Help key opened, ' + keyCode);
                }
            // Add other F-keys here:
            else if((keyCode == 113 || e.key == 'F2') && 
                    !(event.altKey ||event.ctrlKey || event.shiftKey || event.metaKey))
             {
                // prevent code starts here:
                removeDefaultFunction();
                e.cancelable = true;
                e.stopPropagation();
                e.preventDefault();
                e.returnValue = false;
                // Do something else for F2
                alert('F2 key opened, ' + keyCode);
                }
        });
    </script>
</body>
</html>
发布评论

评论列表(0)

  1. 暂无评论