Warm tip: This article is reproduced from stackoverflow.com, please click
asp.net internet-explorer-11 javascript visual-studio-2012 windows-10

getAttribute(value) returns null even when the value exists when running the code locally

发布于 2020-03-31 22:55:32

I'm trying to debug a ASP.Net site. The code is debugged using Visual Studio 2012 and is running locally using IIS Express on my Windows 10 machine. The web application needs to be run using Internet Explorer 11.

When I run the code, I get an exception that is caught by Visual Studio, in the on-page JavaScript (in a piece of code not shown below). I know for a fact that the code is already out in production and it 100% works. However when I debug the code locally it fails to work as expected.

Here's the code in question:

var elements = document.getElementsByTagName('input');
for(var i = 0; i < elements.length; i++) {
    var value = elements[i].getAttribute('value');
    //....
}

When I run the code locally the elements[i].getAttribute('value') returns null. However when I run this same code in production it works fine. When I debug the code, I can see that the elements[i] has an actual value stored in the "value" attribute, however the above code still returns null.

I'm not allowed to change the code (due to reasons) and since my colleague is able to run the code on his machine using the same setup, I'm inclined to think it's a configuration issue on my machine in either Visual Studio or something else.

I'm open to any suggestions as to what might be the cause.

Questioner
Toni Kostelac
Viewed
85
Toni Kostelac 2020-01-31 19:22

After a bit more searching and talking to my colleagues I was advised to turn on Enterprise Mode (Tools -> Enterprise Mode) in Internet Explorer.

This, according to this article, renders the page like it would have been rendered in IE8. From what I can tell it also resolves the issue I was seeing.

I hope this can help someone in the future.