简体   繁体   中英

document.all is not working in Firefox

I am working on an old project for maintenance. I found that document.all is not working in Firefox 25. And I am getting the error below.

TypeError: document.all.TabularDataControlAttivitta.object is undefined

And my sample code is:

document.all.TabularDataControlProj.object.Filter = 'COMPANYCODE=' + compValue;
document.all.TabularDataControlProj.object.Reset();
document.getElementById('cmbActivity_' + rowNo).options.length = 1;
if (document.getElementById('cmbProject_' + rowNo).options.length > 0) {
    for (var i = document.getElementById('cmbProject_' + rowNo).options.length - 1; i >= 0; i--) {
        document.getElementById('cmbProject_'+rowNo).options[i] = null;
    }
}
if (document.all.TabularDataControlProj.recordset.recordcount > 0) {
    document.all.TabularDataControlProj.recordset.movefirst;
}
pOption = new Option('-Select-', -1);
document.getElementById('cmbProject_' + rowNo).add(pOption);
while (document.all.TabularDataControlProj.recordset.eof == false) {
    Optionp = new Option((document.all.TabularDataControlProj.recordset.fields(0) + ' - ' + document.all.TabularDataControlProj.recordset.fields(2)), document.all.TabularDataControlProj.recordset.fields(0));
    document.getElementById('cmbProject_' + rowNo).add(Optionp);
    document.getElementById('cmbProject_' + rowNo).selectedIndex = indxAct;
    document.all.TabularDataControlProj.recordset.movenext;
    }
}

Any patch or solution for this? Because it's very difficult to edit the entire project.

document.all is non-standard. It was a Microsoft-specific feature that they added to IE. Most other browsers have never supported it.

Even in IE it is now deprecated. You should not be using it.

(your old project must be very old, because this has been the case for quite some time now)

For most cases, you can use document.getElementById() instead.

If you're using document.all to get an element using it's ID value then document.getElementById() is a direct replacement.

If you're using document.all to get an element some other way, then I recommend switching to getting it by ID (add an ID if necessary).

I note that the way you're using the element makes it look like it may be an activeX control? (ie I see stuff like .object.Filter , .recordset.movefirst , etc)

If that is the case, then you need to be aware that Firefox does not support activeX controls at all. They are also specific to IE. If it is an activeX control and you need it to work in Firefox then unfortunately, you probably have quite a lot of rewriting ahead of you.

Document.all Provides access to all elements with an id. This a legacy non-standard interface, you should use the document.getElementById() method instead.

Ref: https://developer.mozilla.org/en/docs/Web/API/Document

As the error states, the problem is not with document.all not working (it does), it's with document.all.TabularDataControlAttivitta.object being undefined. This could be either because of application-specific reasons (you simply don't define an object expando), or because you have several elements with name or id equal to TabularDataControlAttivitta.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM