Document.all no firefox

11 respostas
Kassiane_Pretti

Olá pessoal,

estou precisando alterar um sistema web para garantir a compatibilidade no IE e firefox.

Tem um código javascript assim:

function f1()
{
       var elements = document.all;
		        for(var i = 0; i<elements.length;i++){
		            if(elements[i].type == "checkbox"){
		            	if (elements[i].checked == true){
							return true;
						}
		            }
		        }
}

Fazendo algumas investigações, pude perceber que o document.all não funciona no firefox e sim, somente no IE. Gostaria de saber se alguém
pode me ajudar com essa situação.

Desde já agradeço a todos.

Att

11 Respostas

charlesbraw

Para substituir esse document.all, você pode utilizar o getElementsByTagName.

Verifica se esse código te atende:

var input = document.getElementsByTagName("input");

	for(var i=0; i<input.length; i++) {
		 if(input[i].type == "checkbox"){  
			 if (input[i].checked == true)
				 return true; 
		 }
	}
Kassiane_Pretti

Vou testar.

Kassiane_Pretti

charlesbraw, serviu perfeitamente.

Att

ViniGodoy

Ei, Kassiane, você passou um tempo sumida do fórum, não?

charlesbraw

Que bom que funcionou.

Realmente Kassiane document.all é só para IE.
Onde trabalhos temos muitos problemas com CSS e Javascript pelo fato dos navegadores não seguirem o mesmo padrão.
O IE tem outro problema, algumas coisas de layout são renderizadas de maneira diferente conforme muda a versão.

E

Boa noite....

Estou passando pelo mesmo problema. Descobri que um recurso do site que estou desenvolvendo não funciona justamente por causa do document.all.

Uso o script para recuperar dados sem dar refresh na página. Ví a dica do amigo aí em cima, mas não sei como implementar no meu código, alguém pode me ajudar? Desde já, agradeço.

Fico no aguardo,

<script type="text/javascript">
		
		// A função abaixo pega a versão mais nova do xmlhttp do IE e verifica se é Firefox. Funciona nos dois.
		function createXMLHTTP() 
		{
		    try 
		    {
		        ajax = new ActiveXObject("Microsoft.XMLHTTP");
		    } 
		    catch(e) 
		    {
		       try 
		       {
		            ajax = new ActiveXObject("Msxml2.XMLHTTP");
		            alert(ajax);
		       }
		       catch(ex) 
		       {
		           try 
		           {
		                ajax = new XMLHttpRequest();
		           }
		           catch(exc) 
		           {
		                alert("Seu navegador não tem recursos para uso do Ajax.");
		                ajax = null;
		           }
		       }
		       return ajax;
		    }
		
		var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
		"MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
		"Microsoft.XMLHTTP"];
		for (var i=0; i < arrSignatures.length; i++) {
		    try {
		        var oRequest = new ActiveXObject(arrSignatures[i]);
		            return oRequest;
		        } catch (oError) {
		    }
		}
		
		throw new Error("MSXML is not installed on your system.");
		} 
		
		function RetornaDestinos(periodorota)
		{
		    var oHTTPRequest = createXMLHTTP(); 
		    oHTTPRequest.open("post", "retorna_destinos.asp", true);
		    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		    oHTTPRequest.onreadystatechange=function() {
		       if (oHTTPRequest.readyState==4){
		        document.all.exibedestino.innerHTML = oHTTPRequest.responseText;
		       }
		}
		
		oHTTPRequest.send("periodorota=" + periodorota);
		
		}	


		function RetornaRotas(destinorota)
		{
		    var oHTTPRequest = createXMLHTTP(); 
		    oHTTPRequest.open("post", "retorna_rotas.asp", true);
		    oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		    oHTTPRequest.onreadystatechange=function() {
		       if (oHTTPRequest.readyState==4){
		        document.all.exiberotas.innerHTML = oHTTPRequest.responseText;
		       }
		}
		
		oHTTPRequest.send("destinorota=" + destinorota);
		
		}	


</script>
charlesbraw

ederpardeiro

Está funcionando em algum navegador?

esse “document.all.exiberotas.innerHTML” provavelmente refere-se ao uma div.

se for, use o document.getElementById(‘exiberotas’).

Explica o erro pra gente.

Valeu.

E

Bom dia Charlesbraw,

É isso mesmo, se trata de uma div e o problema se resolve utilizando document.getElementById

Muito obrigado

A

Pessoal desculpa ressucitar o tópico mas encontro o mesmo problema, e não consigo resolver:

o código serve pra eu mudar o menu que aparece quando clico com botão do mouse direito,

function abremenu(x){
	if (IE) {
	document.all.divinfos[x-1].style.visibility="hidden";
	document.all.divinfos[x-1].style.display='';
	document.all.divinfos[x-1].style.filter="blendTrans(duration=.5)";
	document.all.divinfos[x-1].filters.blendTrans.Apply();
	document.all.divinfos[x-1].style.visibility="visible";
	document.all.divinfos[x-1].filters.blendTrans.Play();
	}
}

function fechamenu(x){
	if (IE) {
	document.all.divinfosdivinfos[x-1].style.visibility="hidden";
	document.all.divinfosdivinfos[x-1].style.display='none';
	}
}

ele funciona no IE e no CHROME, e ele tem o tal termo document.all, mas não sei como utilizar o document.getelementbyid ou bytagname… ajuda

E

Boa tarde Andrei,

Troque o document.all.divinfosdivinfos por document.getElementById(‘divinfosdivinfos’)
A M.e.r.d.a do Firefox não reconhece o document.all

Valeuu…

A

olá eder… problema resolvido obrigado!

Criado 22 de outubro de 2010
Ultima resposta 10 de jun. de 2011
Respostas 11
Participantes 5