{"id":246,"date":"2011-07-15T19:03:45","date_gmt":"2011-07-15T13:33:45","guid":{"rendered":"http:\/\/vikku.info\/codesnippets\/?p=246"},"modified":"2011-07-15T19:04:29","modified_gmt":"2011-07-15T13:34:29","slug":"why-javascript-historyback-toggles-between-two-pages","status":"publish","type":"post","link":"http:\/\/vikku.info\/codesnippets\/javascript\/why-javascript-historyback-toggles-between-two-pages\/","title":{"rendered":"why javascript history.back() toggles between two pages"},"content":{"rendered":"<p>I was working in a project where each page had a back button. Because of the designers design the back button was created using anchor tag &lt;a&gt; and as a programmer i thought of using the back button like the following in the anchor tag.<\/p>\n<pre lang='html'>\r\n<a href='javascript:;' onclick='window.history.back()'>Back<\/a>\r\n<\/pre>\n<p>But what had happened when i press the back button after navigating to various pages was i got locked between the last two navigated pages. It kept toggling between the last visited page and the previous page where as it is supposed to go backward step by step.<\/p>\n<p>So let us say i have navigated from page 1 to 10 and now i am in page 10. When i press the back button in page 10 i came to page 9. But when i pressed the back button in page 9 again it took me to page 10 instead of taking me to page 8. So this keeps happening until i changed the code to the following.<\/p>\n<pre lang='html'>\r\n<a href='javascript:window.history.back();'>Back<\/a>\r\n<\/pre>\n<p>After modifying to the above code all went well. The back button press worked normal which took me from page 10 all the way to page 1 when i kept on pressing the back button.<\/p>\n<p>and besides the given code there was a style applied to the anchor tag and that was just float right.<\/p>\n<p>Is this an issue needed attention which is to be posted in a blog? I don&#8217;t think so but thought of talking to the people to see their responses. If people know why this peculiar behaviour then please post a note of a reply or a reference or whatever which could be of assistance to all people. \ud83d\ude42 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was working in a project where each page had a back button. Because of the designers design the back button was created using anchor tag &lt;a&gt; and as a programmer i thought of using the back button like the following in the anchor tag. Back But what had happened when i press the back [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/246"}],"collection":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/comments?post=246"}],"version-history":[{"count":2,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/246\/revisions"}],"predecessor-version":[{"id":248,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/246\/revisions\/248"}],"wp:attachment":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/media?parent=246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/categories?post=246"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/tags?post=246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}