Foros del Web » Programando para Internet » Javascript » Frameworks JS »

DIV siempre visible, pushstate + ajax o similar, NO CSS

Estas en el tema de DIV siempre visible, pushstate + ajax o similar, NO CSS en el foro de Frameworks JS en Foros del Web. Hola, Como último recurso, acudo a ustedes. Llevo días y días, buscando algo para que un DIV [section] siempre este visible, aunque recargues el contenido, ...
  #1 (permalink)  
Antiguo 02/06/2012, 16:37
 
Fecha de Ingreso: enero-2011
Mensajes: 12
Antigüedad: 13 años, 3 meses
Puntos: 1
Busqueda DIV siempre visible, pushstate + ajax o similar, NO CSS

Hola,
Como último recurso, acudo a ustedes.

Llevo días y días, buscando algo para que un DIV [section] siempre este visible, aunque recargues el contenido, es decir, igual que el chat de Facebook.

He buscado por todo este foro, en foros en ingles, "Googleando", etc etc, y lo unico que consigo encontrar son codigos que no funcionan, CSS (position:fixed;) o simplemente códigos FRAMESET... pero no doy con lo que quiero.

En este foro encontre el siguiente codigo ([URL="http://www.forosdelweb.com/f18/mantener-div-visible-cuando-cambia-url-976843/"] Mantener un div Visible cuando cambia la url[/URL]) [Podeis ver el codigo en el post del usuario @elulice, post numero #16]

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. }

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

Creo que ese código podría funcionar, pero no consigo que funcione correctamente.

Explico exactamente lo que quiero hacer:

1. Cargar el contenido en DIV, dejando a un DIV siempre fijo, aunque cambies de URL

2. Al cargar el nuevo contenido, que aparezca la URL de ese contenido

3. Que no use FRAMESET, iframe...

4. Que sea similar o a porder ser, igual que algunos ejemplos abajo.

5. NO quiero position:fixed;

Por favor, alguien me podría ayudar.

Les dejo algunos ejemplos de lo que me gustaría hacer.

[URL="http://www.beatport.com/"]Beatport[/URL] Al dar play a cualquier canción, puedes navegar por todo el portal, sin que pare de sonar la música, y cambiando la URL.

[URL="http://www.facebook.com"]Facebook[/URL] el chat se mantiene fijo, sin que cambie el "contenido".

[URL="https://plus.google.com/"]Google+[/URL] cuando navegas por la red social, el contenido carga en un div, y ademas cambiar la URL.

Muuuuuuuchas gracias de antemano

Última edición por wwwshowdjes; 02/06/2012 a las 17:49 Razón: URLs incorrectas
  #2 (permalink)  
Antiguo 02/06/2012, 17:49
 
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

Al fin!!! ya lo solucione...

En un momento os dejo el código.
  #3 (permalink)  
Antiguo 03/06/2012, 06:18
 
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

Etiquetas: ajax, beatport, chat, div+section, facebook, fijo, google, html5, siempre, google
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:14.