Ver Mensaje Individual
  #16 (permalink)  
Antiguo 24/02/2012, 03:07
elulice
 
Fecha de Ingreso: octubre-2011
Mensajes: 18
Antigüedad: 12 años, 6 meses
Puntos: 1
Respuesta: Mantener un div Visible cuando cambia la url

Lo que yo hice fue esto
Código Javascript:
Ver original
  1. $(document).ready(function() {
  2.     if (typeof window.history.pushState == 'function') {
  3.         pushstate();            
  4.     }else{
  5.         check(); hash();
  6.     }
  7. });
  8. // AJAX mágico que cambia la url;
  9.  
  10. function ajaxMagic(i,o){
  11.     var ajax = new XMLHttp();
  12.     with(ajax){
  13.         open("POST",i,true);
  14.         setRequestHeader("Content-type","application/x-www-for-urlencoded");
  15.         send(null);
  16.  
  17.         onreadystatechange = function(){
  18.             if((readyState == 4) && (status == 200)){
  19.                 respF = responseText;
  20.                 if(respF != ""){
  21.                     document.getElementById(o).innerHTML = respF;
  22.                 }
  23.             }
  24.         }
  25.         }
  26. }
  27.  
  28.  
  29. function check(){
  30.     var direccion = ""+window.location+"";
  31.     var nombre = direccion.split("#!");
  32.     if(nombre.length > 1){
  33.         var url = nombre[1];
  34.         alert(url);
  35.     }
  36. }
  37.    
  38. function pushstate(){
  39.     var links = $("a");
  40.     links.live('click', function(event) {
  41.         var divToChg = $(this).attr('ejemplo'); //este atributo no es valido en el TAG A pero lo creo igual
  42.         var url = $(this).attr('href');
  43.         history.pushState({
  44.             path: url
  45.         }, url, url);
  46.         ajaxMagic(url,divToChg)
  47.         return false;
  48.     });
  49.        
  50.     $(window).bind('popstate', function(event) {
  51.         var state = event.originalEvent.state;
  52.         if (state) {
  53.             alert(state.path);
  54.         }
  55.     });
  56. }
  57.    
  58. function hash(){
  59.     $(window).bind("hashchange",function(){
  60.         var hash = ""+window.location.hash+"";
  61.         hash = hash.replace("#!","")
  62.         if(hash != ""){
  63.             alert(hash);
  64.     }
  65.     });
  66.  
  67.     $("a").bind('click', function(e) {
  68.         e.preventDefault();
  69.         var url = $(this).attr('href');
  70.         window.location.hash = "#!"+url;
  71.         return false
  72.     });
  73. }

y en el tag <a> tendría que ser así

Código HTML:
Ver original
  1. <a href='loquesea.php' ejemplo='divDondeSeMostraraElResultado'>prueba</a>

Última edición por elulice; 24/02/2012 a las 03:13