Elementos Historial

Hola de nuevo, es otra pregunta sobre el objeto history, pero un poco más pulida. ¿Cómo puedo obtener los elementos (páginas) del objeto history?, he intentado todo y siempre los valores mostrados son 'undefined', por ejemplo, he intentado recorrer la colección como se hace sobre cualquier objeto (como si fuera un array), o sea objeto.item, también directamente he intentado obtener la url anterior así: var mivar=history.back(); pero nunca obtengo ningún valor definido. No sé si no centro bien las cosas o es que realmente no sé puede... Bueno espero tu respuesta
Respuesta
1
Como te comenté, por motivos de seguridad se impide acceder explícitamente a la información de la historia de navegación. En IExplorer no se puede, pero
En Netscape con los permisos necesarios se puede accediendo mediante las propiedades:
- Current
- next
- Previous
Del objeto history
Un saludo Solrac, parece que es cierto, o por lo menos eso dirían las horas que he gastado haciendo pruebas. Lo que estoy intentando ahora es capturar el evento de salida y procesar una función que reditija la página de destino. El objeto location ofrece más posibilidades.
Gracias por todo y un cordial saludo. Miguel.

1 respuesta más de otro experto

Respuesta
1
Aquí tienes un ejemplo de cómo estraer los valores del objeto history, no creo que tengas problemas porque está bastante facil. Tu fallo es que debes de especificar el objeto window antes del history. Porque el objeto history es distinto dependiendo de la página que esté abierta. De todas maneras prueba el ejemplo este. Un saludo
<!-- This file implements a navigation bar, designed to go in a frame at
the bottom of a window. Include it in a frameset like the following:
<frameset rows="*,75">
<frame src="about:blank">
<frame src="navigation.html">
</frameset>
-->
<SCRIPT>
// The function is invoked by the Back button in our navigation bar.
function go_back()
{
// First, clear the URL entry field in our form.
document.navbar.url.value = "";
// Then use the History object of the main frame to go back.
parent.frames[0].history.back();
// Wait a second, and then update the URL entry field in the form
// from the location.href property of the main frame. The wait seems
// to be necessary to allow the location.href property to get in sync.
setTimeout("document.navbar.url.value = parent.frames[0].location.href;",
1000);
}
// This function is invoked by the Forward button in the navigation bar.
// It works just like the one above.
function go_forward()
{
document.navbar.url.value = "";
parent.frames[0].history.forward();
setTimeout("document.navbar.url.value = parent.frames[0].location.href;",
1000);
}
// This function is invoked by the Go button in the navigation bar, and also
// when the form is submitted (when the user hits the Return key).
function go_to()
{
// Just set the location property of the main frame to the URL
// that the user typed in.
parent.frames[0].location = document.navbar.url.value;
}
</SCRIPT>
<!-- Here's the form, with event handlers that invoke the functions above. -->
<FORM NAME="navbar" onSubmit="go_to(); return false">
<INPUT TYPE="button" VALUE="Back" onClick="go_back();">
<INPUT TYPE="button" VALUE="Forward" onClick="go_forward()">
URL:
<INPUT TYPE="text" NAME="url" SIZE=50">
<INPUT TYPE="button" VALUE="Go" onClick="go_to()">
</FORM>

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas