Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Filipe B.

Script Não funciona no IE... Apenas nele >.<

Recommended Posts

 <script src="jquery.js"></script>
   <script>
 $(document).ready(function(){
     $("a").each(function() {
	   var href = $(this).attr('href=http://');
          $(this).attr("target", "_blank");
}
 </script>
 <script>
 $(document).ready(function(){
     $("a").each(function() {
          var href = $(this).attr('href');
          $(this).attr('href','javascript:void(0)');
          $(this).click(function(){
               $('#content').html("");
      	    	$("#carregando").show('slow');
                $.get( href , function(data){
                       $('#content').html(data);
                       $("#carregando").hide('slow');
                });
               return null;
	   });
       });

});
 </script>

 

 

As páginas carregam normalmente em todos os navegadores menos no IE, mas como sou novato posso ter errado em algo. No IE a DIV content onde deveriam ser carregadas as páginas fica duplicada e as páginas não são lidas. E o menu do topo também fica sem funcionar... Só no IE nos outros tudo funciona normal.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Faça assim:

<script src="jquery.js"></script>
<script>
 $(document).ready(function(){
     $("a").each(function() {
          var href = this.toString(); //converte o link para string
          $(this).click(function(e){
               e = e || window.event;
               e.preventDefault(); //Previne que o link seja carregado normalmente

               $("#carregando").show('slow');
                $.get( href , function(data){
                       $('#content').html(data);
                       $("#carregando").hide('slow');
                });
               return null;
                  });
       });

       });
 </script>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ainda não funciona no IE, continua duplicando a DIV content e o menu topo não abre as páginas :/ Será incompatibilidade do script com o navegador? Podeira me dár uma luz? rs

Compartilhar este post


Link para o post
Compartilhar em outros sites

Está em algum servidor? Tem o endereço?

 

 

www.pmsmm.rj.gov.br/teste

 

esse aplicativo de notícias funciona em todos os navegadores mas no IE ai ele duplica a div content

 

links ativos no teste:

Legislação (menu horizontal)

 

Governo->Estrutura->Sec. de Administração (Menu Lateral)

 

Está aparecendo um erro que a div alvo não foi encontrada mas ela está mencionada corretamente no cógido.

 

Ps.: Estou usando um script da net lá vai:

/* Ajax */
function GetXMLHttp() { 
       var xmlHttp; 
       try {                 
               xmlHttp = new XMLHttpRequest(); 
       } 
       catch(ee) { 
               try {   

                       xmlHttp = new ActiveXObject("Microsoft.XMLHttp"); 
               } 
               catch(e) { 
                       try {      

                               xmlHttp = xmlhttp=new ActiveXObject("MSXML2.XMLHttp"); 
                       } 
                       catch(e) { 
                                   alert("Seu browser não suporta AJAX!");                                    
                                   xmlHttp = false; 



                       } 
               } 
       } 
       return xmlHttp; 
} 

var xmlRequest = GetXMLHttp();

 

/* Funcção */
function abrirPag(valor){ 
       var url = valor; 

           xmlRequest.open("GET",url,true);  
           xmlRequest.onreadystatechange = mudancaEstado;
           xmlRequest.send(null);

               if (xmlRequest.readyState == 1) { 
                       document.getElementById("content").innerHTML = "<img src='images/carregando.gif'>"; 
               } 

       return url; 
} 

function mudancaEstado(){ 
       if (xmlRequest.readyState == 4){ 
               document.getElementById("content").innerHTML = xmlRequest.responseText; 
			return false;
       } 
}

 

/* Links estão assim */
<div id="menu" class="round">
<ul>
<li class="style2"><a href="#" onclick="abrirPag('home.php')";>Home</a></span></li>
<li class="style2"><a href="#" onclick="abrirPag('licitacoes.php')";>Licitações</a></li>
<li class="style2"><a href="#" onclick="abrirPag('transparencia.php')";>Transparência</a></li>
<li class="style2"><a href="#" onclick="abrirPag('concurso_publico.php')";>Concurso Público</a></li>
<li class="style2"><a href="#" onclick="abrirPag('legislacao.php');">Legislação</a></li>
<li class="style2"><a href="http://webmail.pmsmm.rj.gov.br/">Webmail</a></li>
</ul></div>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Já resolvi quase tudo, alterei o gerenciador de conteúdo, porém, agora está dando problema com o script que torna o menu clickado com class="active", antes funcionava agora não rs segue código o nome da div onde está o menu é "menu" rs. Diz 'Erro: o divalvo não existe'

 

Script

 //função que troca a classe dos li para ativo e inativo
 function ativoinativo(quem){
  //o 'quem' original é um link, agora tô pegando o li pai
  var lipai = quem.parentNode; 
  if(lipai.className=='active'){
   //se ele já era ativo vira inativo
   lipai.className = 'inativo';
  }else{
   //se ele não tinha classe ainda, transformo em ativo
   lipai.className = 'active';
   //e também faço seus irmãos li virarem inativos
   var irmaosli = lipai.parentNode.childNodes; //pegando os irmaos li
   for(var i=0; i<irmaosli.length ; i++){ //varrendo os li
    var liatual = irmaosli[i];
    if(liatual != lipai && liatual.nodeName=='LI'){
     //se não é o li atual vai virar inativo
     irmaosli[i].className = 'inativo'
    }
   }
  }
 }

 //função que testa qual li que tem o link atual e marca como ativo
 function initAtivoInativo(menu){
  if(!menu.nodeName){
  //testando se o divalvo já é um objeto
  //se não for, eu uso o velho getElementById
   menu = document.getElementById(menu);
   if(!menu){ alert('Erro: o divalvo não existe'); return;}
  }
  //pegando os li que tão dentro do divalvo
  var ah,lis = divalvo.getElementsByTagName('li');
  for(var i=0; i<lis.length ; i++){

   //pegando os links que tão dentro de cada li
   ah = lis[i].getElementsByTagName('a')[0];
   if(!ah){ continue; } //se não achou o link vai pro prox li

   //ativando o onclick nos links pra fazer a troca de ativo/inativo
   ah.onclick = function(e){
    //pegando o alvo crossbrowser http://elcio.com.br/crossbrowser/#7
    if(typeof(e)=='undefined')var e=window.event; 
    source=e.target?e.target:e.srcElement; //
    if(source.nodeType == 3)source = source.parentNode
    //ativando o onclick nos links pra fazer a troca de ativo/inativo
    ativoinativo(source);
   }

   if(location.href.indexOf(ah.href)>-1){
    //se o endereço atual tem o link do li atual marco ativo
    lis[i].className = 'active'
   }else{
    //senão é inativo
    lis[i].className = 'inativo'
   }
  }
 }
 //ativando no onload (mas depois de um tempinho pra não bugar em alguns browsers heheh)
 //você pode usar body onload tb ou onready de libs
 window.onload = setTimeout(function(){initAtivoInativo('menu');},300);

 

HTML

 <div id="menu" class="round">
               <ul>
                       <li class="style2"><a href="#" onclick="abrirPag('arquivos/home.php')";>Home</a></span></li>
                       <li class="style2"><a href="#" onclick="abrirPag('arquivos/licitacoes.php')";>Licitações</a></li>
					<li class="style2"><a href="#" onclick="abrirPag('arquivos/transparencia.php')";>Transparência</a></li>
					<li class="style2"><a href="#" onclick="abrirPag('arquivos/concurso_publico.php')";>Concurso Público</a></li>
					<li class="style2"><a href="#" onclick="abrirPag('arquivos/legislacao.php')";>Legislação</a></li>
                       <li class="style2"><a href="http://webmail.pmsmm.rj.gov.br/" target="_blank">Webmail</a></li>
</ul></div>

 

Classes

<style>
#menu .inativo a {
       padding: 5px 6px;
font-size: 17px;
color: #FFF;
text-decoration: none;
	}

#menu a:hover {
behavior: url(border-radius.htc);
-webkit-border-radius: 10px 0;
-khtml-border-radius: 10px 0;
-moz-border-radius: 10px 0;
border-radius: 10px 0;
background: #74AED7;
	}

#menu .active a {
behavior: url(border-radius.htc);
-webkit-border-radius: 10px 0;
-khtml-border-radius: 10px 0;
-moz-border-radius: 10px 0;
border-radius: 10px 0;
padding-top: 7px;
padding-bottom: 5px;
padding-right: 1,8px;
padding-left: 1,8px;
background-color:#142B34; 
}
</style>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.