Ver Mensaje Individual
  #3 (permalink)  
Antiguo 03/06/2012, 06:18
wwwshowdjes
 
Fecha de Ingreso: enero-2011
Mensajes: 12
Antigüedad: 13 años, 3 meses
Puntos: 1
Respuesta: DIV siempre visible, pushstate + ajax o similar, NO CSS

Aquí os dejo el código en un ejemplo, cualquier duda o problema, preguntarme.

Si alguien puede mejorar el codigo, que no dude en decirlo, :)

Código Javascript:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Codigo by http://www.showdj.es</title>
  6.  
  7.  
  8.  <!--Codigo by http://www.showdj.es -->
  9.  
  10.     <script type="text/javascript" src="http://www.jose-aguilar.com/scripts/jquery/ajax-link/js/jquery-ui-1.8.6.min.js"></script><!--Descargar este escript y alojarlo en vuestro hosting-->
  11.     <script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script><!--Script para Actualizar -->
  12.  
  13.        
  14.     <script type="text/javascript">
  15.     //Este es el script que carga el contenido en un DIV
  16.     $(document).ready(function() {
  17.         //Puedes cambiar la siguiente linea por: $('#DID del div del link').click(function(){
  18.         $('a').live('click', function(event) {
  19.             $("#wrapper").load($(this).attr("href") );
  20.         });
  21.        
  22.     //El anterior bloque, puedes cambiarlo por esto:   
  23.     //$.ajax({
  24.         //type: "POST",
  25.         //url: "hola.php",
  26.         //success: function(a) {
  27.                 //$('#div-results').html(a);
  28.         //}
  29.        //});
  30.     });
  31.     </script>
  32.    
  33.     <!--NO CAMBIAR NADA DEL SIGUIENTE CODIGO, si no sabes-->
  34.    
  35.     <script type="application/javascript">
  36.         $(document).ready(function() {
  37.             // Para navegadores que soportan la función.
  38.             if (typeof window.history.pushState == 'function') {
  39.                 pushstate();            
  40.             }else{
  41.                 check(); hash();
  42.             }
  43.         });
  44.         // Chequear si existe el hash.
  45.         function check(){
  46.             var direccion = ""+window.location+"";
  47.             var nombre = direccion.split("#!");
  48.             if(nombre.length > 1){
  49.                 var url = nombre[1];
  50.                 //alert(url);
  51.             }
  52.         }
  53.        
  54.     function pushstate(){
  55.             var links = $("a");
  56.             // Evento al hacer click.
  57.             links.live('click', function(event) {
  58.                 var url = $(this).attr('href');
  59.                 // Cambio el historial del navegador.
  60.                 history.pushState({ path: url }, url, url);
  61.                 // Muestro la nueva url
  62.                 // alert(url);
  63.                 return false;
  64.             });
  65.            
  66.             // Función para determinar cuando cambia la url de la página.
  67.             $(window).bind('popstate', function(event) {
  68.                 var state = event.originalEvent.state;
  69.                 if (state) {
  70.                     // Mostrar url.
  71.                     // alert(state.path);
  72.                 }
  73.             });
  74.         }
  75.        
  76.         function hash(){
  77.             // Para IE
  78.             // Función para determinar cuando cambia el hash de la página.
  79.             $(window).bind("hashchange",function(){
  80.                 var hash = ""+window.location.hash+"";
  81.                 hash = hash.replace("#!","")
  82.                 if(hash && hash != ""){
  83.                     alert(hash);
  84.                 }
  85.             });
  86.             // Evento al hacer click.
  87.             $("a").bind('click', function(e) {
  88.                 e.preventDefault();
  89.                 var url = $(this).attr('href');
  90.                 // Cambio el historial del navegador.
  91.                 window.location.hash = "#!" + url;
  92.                 return false
  93.             });
  94.         }
  95.         </script>  
  96.  
  97.   </head>
  98.   <body>
  99.     <a href='home' id="en caso de asignarle un ID especifivo">prueba</a> <object type="application/x-shockwave-flash" data="http://media.showdj.es/data/dewplayer.swf" width="240" height="20" id="dewplayer" name="dewplayer"><param name="wmode" value="transparent"><param name="movie" value="http://samples.showdj.es/data/dewplayer.swf"><param name="flashvars" value="mp3=http://listen.radionomy.com/showdj-music&amp;autostart=0&amp;autoreplay=0&amp;showtime=1&amp;randomplay=1&amp;nopointer=1"></object><!--Podeis poner play y comprobar que carga la web, sin parar la musica-->
  100.  
  101.     <div id="wrapper"> <!--Aquie es donde se mostrara la url de HOME--> </div>
  102.   </body>
  103. </html>

Ambos script sacan la URL de href='home'.

Tener cuidado con la publicidad de vuestra web/blog, porque a mi me ha dado problemas.

Última edición por wwwshowdjes; 03/06/2012 a las 06:21 Razón: Error en el codigo