Problems with javascript when reading getElementByID in IE and Chrome

0

I have an interesting problem and did not know of this condition in IE. There is in the site that I got for maintenance, a call like this: document.getElementByID(...) . Well, what happens is that IE is not getting ID , but Name , because there is no ID and yes Name. Well, in Chrome this does not work (correct). What I did, I changed calls to: document.getElementsByName(...) . Well, it should work and it does not work. Give this error over jquery-ui.min.js :

Uncaught TypeError: a.plugins[n].push is not a function

This is my js code. The element is IFConsultaEmpresa_ :

if (pObjAsp != 'X') {
         pagina = pTxtDiretorio + pObjAsp + '?pt=' + pTxtNomeFuncao + p_parametros;

         var cp = new cpaint();
         cp.set_transfer_mode('get');
         cp.set_debug(false);
         cp.call('../../atc/asp/atc0006c.asp', 'auxHistNavegacao', '', pCodFuncao, pTxtDiretorio, pTxtNomeFuncao, pNumeroIframe);

         //torna o iframe invisivel
         for (var i = 1; i <= qtd_iframe; i++) {
               //eval('document.getElementById(\'IFConsultaEmpresa_' + i + '\').height = \'0%\';');

               //Essa alteração para ByName foi necessária para funcionar no Chrome
               eval('document.getElementsByName(\'IFConsultaEmpresa_' + i + '\').height = \'0%\';');
               eval('document[\'all\'].IFConsultaEmpresa_' + i + '.style.display = \'none\';');
         }
         eval('boolIFrame = (IFConsultaEmpresa_' + pNumeroIframe + '.location == \'about:blank\')');

         form01.ifram_carregado.value = 'IFConsultaEmpresa_' + pNumeroIframe;

         if (pCodFuncao == 'ATC84.5.4' || pCodFuncao == 'ATC84.5.5' || pCodFuncao == 'ATC84.5.6' ||
               pCodFuncao == 'ATC84.2.2.2' || pCodFuncao == 'ATC84.2.2.3' ||
               pCodFuncao == 'ATC84.8.2.1' || pCodFuncao == 'ATC84.8.2.2'
            ) {
               boolIFrame = true;
         }

         if (!boolIFrame & pNumeroIframe == '1') {
               //iframe1 exclusívo para abertura/encerramento de atendimento - alteração novo atendimento
               boolIFrame = true;
         }
         if (boolIFrame) {
               eval('document[\'all\'].IFConsultaEmpresa_' + pNumeroIframe + '.src = \'' + pagina + '\';');
         }
         eval('document[\'all\'].IFConsultaEmpresa_' + pNumeroIframe + '.style.display = \'\';');
          //eval('document.getElementById(\'IFConsultaEmpresa_' + pNumeroIframe + '\').height = \'50%\';');

          //Colocado para funcionar no Chrome
         eval('document.getElementsByName(\'IFConsultaEmpresa_' + pNumeroIframe + '\').height = \'50%\';');
      }
   }
   try {
      window.parent['roteiro'].location = '../../ace/ace040a.asp?cod_funcao=' + pCodFuncao;
   } catch (e) {}
   if (form01.ind_visualiza_roteiro.value == 'S') {
      try {
         parent.document['all'].td_roteiro.style.display = '';
      } catch (e) { }
   }
}

Here is my html with this element:

<iframe width="100%" height="0%" scrolling="auto" name="IFConsultaEmpresa_<%Response.write intI%>" id="Iframe2" src="about:blank" frameBorder="no" style="display:" >
    </iframe> 

See IFConsultaEmpresa_ is the name and not the ID. How do I resolve this?

    
asked by anonymous 14.09.2015 / 21:05

2 answers

3

I have resolved. Well, not for another person was not possible, even though everyone here guides me along the way. Because I say that. Well, talking here with the person in charge, we had to duplicate the .asp file so it would not impact other calls outside the module. So I changed the ID of the element to the same as the Name. So it was possible to get ByID and it worked. Why duplicate? There is in other parts of the system a call to the old ID, then we duplicate it and leave one file just for the module in the am and the other file for the other modules. A nut solution, but for a site that has been on the air for more than 10 years and suffering patch, we had to do that. The company studies a possibility of rewriting the site, but it takes time. There is high cost involved and the solution is not that simple. The answer for justice should be for ErickGallani, for he is the one who made me see this side of duplication.

    
15.09.2015 / 13:58
0

I'm not sure about the error but what you can do is this

if ( navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ){
  //Faz alguma coisa se for chrome
}

Anything touches and verifies that this function error does not happen for any other particularity.

    
15.09.2015 / 03:08