[thelist] dynamic back button (javascript)

Christian Heilmann lists at onlinetools.org
Wed Feb 9 17:40:27 CST 2005


>
> <html>
> <head>
> <script type="text/javascript">
> function goBack() {
>     var theform = document.getElementById("frmdefault");
>     var previouspage = history(-1);
>
>     theform.method="post";
>     theform.action = previouspage;
>     theform.submit();
> }
> </script>
> </head>
> <body>
> <form name="frmdefault" id="frmdefault">
>     <input type="button" value="Back" onclick="goBack();" />   
>     // other form stuff here....
> </form>
> </body>
> </html>
>
>
> Well, this fails miserably.  :D  I expected it to not work.  But, I 
> can't seem to think of the way to DO that, but have it work.
> firefox's JS tool (which is what i use to test/develop with) says 
> "history is not a function" is the error.

History is an object.
http://www.devguru.com/Technologies/ecmascript/quickref/history.html
Due to security reasons (I guess) the history object only allows you to 
read the length of the internally maintained history array, and to 
navigate via the back() forward() and go() methods. Internally it does 
what you want to do, but you cannot read the history elements.

The "go" method also allows for a string as the parameter, not only an  
integer. It goes to the last page containing the word in the parameter.

Welcome to the world of simulating what browsers do for us, it is a 
tough  living there, and for good reason.






More information about the thelist mailing list