0

Initially the question is does Internet Explorer have some issues calling scripts when launched from a network location, specifically my issue relates to a certain syntax of the script?

I have a group of html files which emulate an archaic system at work using onkeypress or onkeydown events to call a javascript function specifying which page to navigate to when a certain key is pressed.

This is some condensed sample code (for pressing num-pad ENTER) which contains all the elements of the actual file and replicates the exact issue I have:

<!DOCTYPE html>
<html>
<head>
<style>
body {
    margin: 0;
}
img {
    margin: 0;
    border: 0;
}
</style>
    <script>    
        function nav() {
        var x = event.keyCode; 
        var y = event.location;
            if (x == 13 && y === 3) { 
                document.location = "http://www.google.com.au"
                }
            }
    </script>
</head>
<body onkeypress="nav()">
    <map name="test">
        <area href="http://www.google.com.au" title="Alternate naviagion" shape="rect" coords="131,680,160,705">
    </map>
    <img src="ThisPagesImage.png" alt="" usemap="#test">
</body>
</html>

If I launch the file from the desktop it prompts at the bottom of the screen:

Internet Explorer has restricted this webpage from running scripts or ActiveX controls. [Allow blocked content]

If I click "Allow blocked content" the function calls as expected when the num-pad enter is pressed.

However, when launched from a network drive location there is no prompt that scripts or ActiveX controls are restricted and the function is not called. (I also tested replacing document.location = "http://www.google.com.au" with window.alert("Hello World") with the popup appearing when launched from the desktop but not when launched from the network drive.

As such I've determined for whatever reason there must be some network settings (likely to be beyond my control) preventing this from happening.

BUT, the odd thing is if we replace the function with the following there are no issues at all:

function nav() {
var x = event.keyCode; 
    if (x == 13) { 
        document.location = "http://www.google.com.au"
        }
    }

TL/DR

When the html file is launched from a network drive location and the function has 2 conditions if (x == 13 && y === 3) the function is not called however when the function only has one condition if (x == 13) the function is called as expected.

When the html file is launched from the desktop, IE prevents scripts/ActiveX and prompts to allow them and if allowed both functions are called successfully.

NOTE

  1. Internet Explorer is primarally used in my workplace and it is preferred to use IE for these files.
  2. I have no bearing on the setup of the systems or the network, this is simply a way we have been able to achieve some system emulations for training with the little resources we have.
  3. Num-Pad ENTER is preferred to call the function as this emulates the system more accurately.
  4. I did locate a VERY similar question here however it does not answer my/the question (I have also debugged per the comments and no errors are present in the Developer Console).

We are currently using IE Version: 11.0.9600.19002

Samuel Everson
  • 2,097
  • 2
  • 9
  • 24
  • 1
    What is the value of `event.location` when it doesn't work? – H77 May 30 '18 at 02:01
  • @H77 `event.location === 3` (NOTE: `event.location` is assigned to `var y` in the code. We did test by removing the variables from the function with no change in the outcomes. – Samuel Everson May 30 '18 at 02:19
  • 1
    You say that the function works if you check the value of `x`, but not if you check `y`. Are you sure `y === 3` in the case where it does not work? (You could print the value of `y` to the console) – H77 May 30 '18 at 02:23
  • @H77 It turns out to be a compatibility mode issue. As I understand `event.location` is not recognised by IE7 and as compatibility mode renders the page as IE7, the issue we encountered occurred. We followed the breadcrumbs from the Debug Console and ended up [here](https://stackoverflow.com/questions/27272454/ie11-document-mode-defaults-to-ie7-how-to-reset) which drew us to our conclusion. – Samuel Everson May 30 '18 at 02:49

1 Answers1

1

So with great prompting in the comments from @h77 to check the value of y, we discovered the root cause of our issue was IE was displaying intranet sites in compatibility mode.

When paying closer attention to the Debug Console, we noticed the message:

The attached page targets document mode 7. Some console APIs and features may not be available.

This lead me here which sparked my brain into recognising event.location would not be understood by IE7.

As IE11 runs compatibility mode as IE7 and event.location is compatible with IE9 and above, this answers the question.

A solution to this whilst keeping 'Compatibility mode' on you can add <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> in the <head> tag.

Samuel Everson
  • 2,097
  • 2
  • 9
  • 24