Hi Everyone!

 

Bac again with an interesting issue in IE8.  As everyone is aware, F12 is a keyboard shortcut to bring up the Developer Tools in IE8.  Due to application compatibility reasons, one may want to cancel this default behavior to handle his/her own actions.  The following code snippet has been floating around the Internet showing how to cancel this key:

function CancelF12()

{

     var KeyAscii = window.event.keyCode;

     if (KeyAscii == 123)

    {    

        window.event.returnValue = false;

        window.event.keyCode = 0;

    }

}

The above technique works great most of the time.  Last week, we came across a situation where the above code breaks.  Conditions contributing to the failure include:

1. ShowModalDialog() is involved

2. The code must be run in the Internet zone (or Restricted sites zone)

Note the security zone is important here.  The problem goes away if the code is executed in either the Local Intranet or Trusted sites zones.

Repro Steps:

1) Construct test.html and modal.html pages with the following code:

Test.html:

<html>

<body>

<input type="button" onclick="window.showModalDialog('modal.html');" value= "click me">

</body>

</html>

Modal.html:

<html>

<head>

<title>Modal</title>

</head>

<script>

function CancelF12()

{

                       var KeyAscii = window.event.keyCode;

                       if (KeyAscii == 123)

                       {

                                      window.event.returnValue = false;

                                       window.event.keyCode = 0;

                       }

}

</script>

<body onkeydown="CancelF12()">Try pressing F12</body>

</html>

2) Click the button and press F12

After spending some time debugging, the problem turns out to be this setting in the Internet security zone which causes the code to break:  Allow websites to open windows without address or status bars.  It’s disabled by default in the Internet zone, while enabled in both the Local Intranet and Trusted sites zones.  We don’t recommend customers to change the security setting in the Internet zone as that may compromise the security feature set for the entire Internet URL’s.  A better option would be to add that particular URL to the Trusted Sites zone:

 

clip_image001

 

That’s all for now.  Thanks for reading this blog post!

 

Regards,

The IE Support Team