Link to home
Start Free TrialLog in
Avatar of hoogersr
hoogersr

asked on

JavaScript behaviour different on local machine and network share

Good day,

I have a HTML file (see code snippet below) containing JavaScript but the behaviour of the JavaScript in Internet Explorer is different when the file is opened on the local machine than on a network share. When the file is opened in IE from the C drive and the button clicked the alert displays an "undefined" but when the file is opened from a network share using a UNC path in the format \\server\share\file.html the alert displays "test".

When right click in IE on the page the c drive file has a zone of "My Computer | Protected Mode: Off" where the network share has "Local intranet | Protected Mode: Off"

Which setting in IE v11 or the registry must be changed to to get the same behaviour on the C drive as the network share?

Registry keys that comes to mind is:
  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Lockdown_Zones
  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones

Please don't suggest code changes (getAttribute etc) as I am unable to change to code.

Many thanks

<html>
   <head>
      <script type="text/javascript">
		function sayHello(obj) {
		   alert(obj.mess)
		}
      </script>
   </head>
   <body>
      <input type="button" onclick="sayHello(this)" value="Say Hello" mess="test"/>
   </body>
</html>

Open in new window

Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Doesn't work either way for me.

What are you trying to do? What you are doing does not comply with standard practice?

HTML5 provides for custom data attributes - you prefix your attribute name with data-. These values can then be accessed through the dataset property of the HTML node.

This works
<html>
   <head>
      <script type="text/javascript">
		function sayHello(obj) {
		   alert(obj.dataset.mess)
		}
      </script>
   </head>
   <body>
      <input type="button" onclick="sayHello(this)" value="Say Hello" data-mess="test"/>
   </body>
</html>

Open in new window


You said no code changes but you need to ask yourself - what are you gaining by perpetuating a non-standard implementation that is going to cost you time and run the risk of breaking over time.
Avatar of hoogersr
hoogersr

ASKER

Question from above:
What are you trying to do? What you are doing does not comply with standard practice?

Answer:
Thanks for the feedback, unfortunately the code is an example of code used in a large project and the code is riddled with implementations like above. Due to constraints outside my control it is not possible to change the code at this stage.

I am trying to debug the application in VS using the ASP.net Development Server on my local PC and the code fails at the "obj.mess" call. When the code is deployed to IIS on a sever it runs without any issue.
When the code is deployed to IIS on a sever it runs without any issue
The server should not make a difference as the JavaScript is interpreted client side.

You don't want to use getAttribute and I assume you don't want to use jQuery and you can't change the code - not sure what that leaves you with.
The JavaScript is interpreted client side but the difference is that when the file is accessed from the IIS server it runs in the IE zone "Local intranet | Protected Mode: Off". When debugging the application in VS using the ASP.net Development Server on my local PC to IE zone is  "My Computer | Protected Mode: Off".

The two zones can be simulated by opening the file from the C drive and opening the file from a network share using a UNC path in the format \\server\share\file.html. The UNC path must be on another PC/server on the network and not the the local PC.

The IE zone of the page can be verified in IE by right clicking on the page -> properties.

The code works in the "Local intranet | Protected Mode: Off" but not in the  "My Computer | Protected Mode: Off" zone.

What setting in IE v11 or the registry must be changed to to get the same behavior on the C drive as the network share?
I hear you but what I am hearing does not make sense. Why would the code work differently based on the zone - especially when the code you are using is invalid.
It should always return undefined - that is the correct behaviour. You are saying that if you load it through a particular zone it changes the behaviour of the browser to make it run invalid code?

Are you sure you are not dealing with a caching issue - if you do a view source on the two locations (UNC and C drive) is the source code identical?
Thanks for your feedback, The code in both locations are identical, the behavior is different and the only difference I can see is that the zones are different.
When running the code from a network UNC using IE v11 the code displays the alert with the text "test".
I don't see how it can work though - the code should not work. Tried in all browsers against IIS, Network Share and Local drive - in none of those situations can I get it to display anything other than undefined.

When running the code from a network UNC using IE v11 the code displays the alert with the text "test".
See screenshotUser generated image
User generated image
See above for a screen dump of IE 11 displaying "test". The version is lower than yours.
In what internet zone is your code running when accessed through the network UNC path? It must be a UNC path on another computer/server and not the same PC.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect, thanks for your help.
You are welcome.