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
- Internet Explorer is primarally used in my workplace and it is preferred to use IE for these files.
- 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.
- Num-Pad ENTER is preferred to call the function as this emulates the system more accurately.
- 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