Ver Mensaje Individual
  #4 (permalink)  
Antiguo 05/04/2015, 10:14
Avatar de NueveReinas
NueveReinas
 
Fecha de Ingreso: septiembre-2013
Ubicación: No tan Buenos Aires
Mensajes: 1.101
Antigüedad: 10 años, 8 meses
Puntos: 145
Respuesta: Mismo Header para todas las paginas

Algo así: http://jsfiddle.net/rsrc68yq/

Código HTML:
Ver original
  1. <div id="incluir-header"></div>

Código Javascript:
Ver original
  1. $(document).ready(function(){
  2.    
  3.     //Ponemos todo el contenido del header en el contenedor llamado "incluir-header" (o como quieras llamarlo) a través del html de JS
  4. $("#incluir-header").html('<div id="header"><ul><li id="inicio">Inicio</li><li id="pagina1">Página 1</li><li id="pagina2">Página 2</li><li id="pagina3">Página 3</li><li id="pagina4">Página 4</li></ul></div>');
  5.  
  6.     //Comprobamos la URL, por ejemplo, para el index:
  7. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "")
  8. {  $("#inicio").addClass('activo'); };
  9.  
  10. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "index")
  11. {  $("#inicio").addClass('activo'); };
  12.  
  13. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "index.html")
  14. {  $("#inicio").addClass('activo'); };
  15.    
  16.     //Y así con todas las páginas y sus URLs variantes (que terminan con .html o .php por si acceden desde ese enlace)
  17.    
  18.     //Página 1
  19. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "pagina1")
  20. {  $("#pagina1").addClass('activo'); };
  21.    
  22. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "pagina1.php")
  23. {  $("#pagina1").addClass('activo'); };
  24.    
  25.     //Página 2
  26. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "pagina2")
  27. {  $("#pagina2").addClass('activo'); };
  28.    
  29. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "pagina2.php")
  30. {  $("#pagina2").addClass('activo'); };
  31.  
  32.     //Página 3
  33. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "pagina3")
  34. {  $("#pagina3").addClass('activo'); };
  35.    
  36. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "pagina3.html")
  37. {  $("#pagina3").addClass('activo'); };
  38.    
  39.     //Página 4
  40. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "pagina4")
  41. {  $("#pagina4").addClass('activo'); };
  42.    
  43. if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) == "pagina4.html")
  44. {  $("#pagina4").addClass('activo'); };
  45.    
  46. });

Código CSS:
Ver original
  1. /* Estilos de ejemplo */
  2.  
  3. #header {
  4.     max-width:900px;
  5.     padding-top:15px;
  6.     padding-bottom:15px;
  7.     background:#CCC;
  8. }
  9.  
  10. ul {
  11.     list-style:none;
  12.     margin:0;
  13.     padding:0;
  14. }
  15.  
  16. li {
  17.     color:white;
  18.     display:inline-block;
  19.     margin-left:10px;
  20.     margin-right:10px;
  21.     background:#666;
  22.     padding:15px;
  23. }
  24.  
  25. li:hover {
  26.     color:#666;
  27.     background:white;
  28. }
  29.  
  30. .activo {
  31.     color:#666;
  32.     background:white;
  33.     border:1px red solid;
  34. }

De todas formas te aclaro que algo parecido se podría hace en PHP, pero bueno, este ejemplo está hecho en JS.
__________________
¿Te sirvió la respuesta? Deja un +1