anmldr Posted August 8, 2010 Share Posted August 8, 2010 I have some buttons on the bottom of a page. This is essentially an eBook. There is a static button that is the same for all pages that links to the Index page. That works fine. There is a Next button to go to the next page in the book. It is the Back button that I am having problems with.I tried <a href="#" onclick="history.back(); return false;"> but this just goes to the bottom of the previous page---where the buttons are located. How to I specify to go to the top of the page?The reason that I don't link to the previous page in the book is that it is also possible to get to the page by clicking on links elsewhere in the book. People are accustomed to going to the previous page that they viewed and not to the previous page in a book. 90% or more of the time, it will in fact be the previous page in the book but I don't want to disorient the reader by perhaps going to a page that they had not viewed before.Thanks,Linda Link to comment Share on other sites More sharing options...
niche Posted August 8, 2010 Share Posted August 8, 2010 do you have a simplified example of your entire script? Link to comment Share on other sites More sharing options...
real_illusions Posted August 8, 2010 Share Posted August 8, 2010 Why not make the links:"Previous Page" and "Next Page" - so the user knows what to expect when clicking on those links.You could have "Go back to your last viewed page" or something along those lines somewhere, however, people know where the back button is, and know how it works and what to expect, so in a way, there isn't a real neccessity to have this link on a website. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 8, 2010 Share Posted August 8, 2010 wouldn't something like <a href="java script:location.href=document.referrer">BACK</a> be a good optionif you want to go to specific bookmark location you could use <a href="java script:location.href=document.referrer+'#bookmarklocation'">BACK</a> Link to comment Share on other sites More sharing options...
anmldr Posted August 8, 2010 Author Share Posted August 8, 2010 Why not make the links:"Previous Page" and "Next Page" - so the user knows what to expect when clicking on those links.Because the "Back" button would serve 2 purposes. It would in most instances return to the previous page in the book. But, if they arrive at that page from say the Table of Contents page or a link that points to an illustration, they may want to return to the Table of Contents or the page that points to the illustration and not to the previous page in the book.You could have "Go back to your last viewed page" or something along those lines somewhere"Back" is less verbose and takes up less screen space.people know where the back button is, and know how it works and what to expect, so in a way, there isn't a real neccessity to have this link on a website.It won't be a web site. It is a collection of linked documents that will be readable within a native PDA app. There will not be a browser back button.<a href="java script:location.href=document.referrer">BACK</a> Thanks. This is the idea but it does not work.Linda Link to comment Share on other sites More sharing options...
dsonesuk Posted August 8, 2010 Share Posted August 8, 2010 I suppose you did remove the space between javascript which is placed when you use insert special item 'code'. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 8, 2010 Share Posted August 8, 2010 looking into this you need to identify if this page has been referred to, else it will try to link to location.href. so i came up with thisjavascript <script type="text/javascript">/*<![CDATA[*//*---->*/window.onload=function(){if(document.referrer) { if(document.getElementById("backbutton")) { document.getElementById("backbutton").href=document.referrer; } } else { if(document.getElementById("backbutton")) { document.getElementById("backbutton").style.visibility="hidden"; } }}/*--*//*]]>*/</script> back link <a id="backbutton" href="#">BACK</a> Link to comment Share on other sites More sharing options...
anmldr Posted August 9, 2010 Author Share Posted August 9, 2010 I suppose you did remove the space between javascript which is placed when you use insert special item 'code'.I did remove it. Thanks. But it still did not work for some reason. I will look at your other post now.Thanks,Linda Link to comment Share on other sites More sharing options...
thescientist Posted August 9, 2010 Share Posted August 9, 2010 I did remove it. Thanks. But it still did not work for some reason. I will look at your other post now.Thanks,Lindaare you checking for errors? Link to comment Share on other sites More sharing options...
anmldr Posted August 9, 2010 Author Share Posted August 9, 2010 are you checking for errors?I sure did but thanks for asking. It returns to the previous page but at the bottom of the page.Linda Link to comment Share on other sites More sharing options...
dsonesuk Posted August 9, 2010 Share Posted August 9, 2010 I sure did but thanks for asking. It returns to the previous page but at the bottom of the page.Not with my code. surly not! are you clearing the cache? Link to comment Share on other sites More sharing options...
anmldr Posted August 10, 2010 Author Share Posted August 10, 2010 Not with my code. surly not! are you clearing the cache?I edited this post. At first, I thought that the code from post #7 worked perfectly. dsonesuk, what it seems to do is to go to the top of the same page that has the Back button on it rather than going to the top of the referring page.Yes, I did clear the cache and the browser history before starting.Linda Link to comment Share on other sites More sharing options...
dsonesuk Posted August 10, 2010 Share Posted August 10, 2010 I don't understand why its not working? i tried it 3 separate htm pages, it worked.dynamic php index page , which uses url to include content from other pages(index.php?page=gallery, index.php?page=another), and it worked.tested in FF, IE7/8 and even crappy IE6.could we see the whole code of page. Link to comment Share on other sites More sharing options...
anmldr Posted August 10, 2010 Author Share Posted August 10, 2010 I don't understand why its not working? i tried it 3 separate htm pages, it worked.tested in FF, IE7/8 and even crappy IE6.could we see the whole code of page.I think that I figured out (partially) why it is not working for me. I was testing the pages on local files. When I uploaded them to my web site, it worked.Will this script work for local files?Here is what I uploaded. As I mentioned, it works on the web but not on the desktop as local files.http://www.anmldr.com/tThe only thing that I changed is the visibility to visible rather than hidden.LindaP.S. Thank you very much for your patience. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 11, 2010 Share Posted August 11, 2010 Will this script work for local files?That would be "No" I'm afraid, But luckily i know a script that will, a bit bigger! but it works.<script type="text/javascript">/*<![CDATA[*//*---->*/function set_cookie( name, value, days){var cookie_string = name + "=" + escape ( value );if (days){var expires = new Date ();expires.setTime(expires.getTime()+(days*24*60*60*1000));cookie_string += "; expires=" + expires.toGMTString();}document.cookie = cookie_string;}function get_cookie(cookie_name){var results = document.cookie.match( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );if ( results )return ( unescape ( results[2] ) );elsereturn null;}function getPrevPage(){var PreviousPage = get_cookie("CurrentToPrevPage");if(PreviousPage != null){document.getElementById("backbutton").href=PreviousPage;}}function storecurrentpage(currentpage){set_cookie("CurrentToPrevPage", currentpage, 7); //set cookie ref name, value, amount of days to keep cookie}window.onload=function(){linkcontainer=document.getElementById("links");anchorlinks = linkcontainer.getElementsByTagName("A");for(i=0;i<anchorlinks.length;i++){if(anchorlinks[i].id != "backbutton"){anchorlinks[i].onclick = function() {storecurrentpage(location.href)}}}getPrevPage();}/*--*//*]]>*/</script> what this will do is when the page loads it will assign a onclick function to all anchor links Except the one with id="backbutton", then, when clicked, a cookie is created that will store the current page, (which will become the previous page, when the selected page is opened) and add to the href of backbuttton. <div id="links"><a id="backbutton" href="java script:void(null)">BACK</a> <a href="page1a.htm">page1</a> <a href="page2a.htm">page2</a></div> Link to comment Share on other sites More sharing options...
anmldr Posted August 11, 2010 Author Share Posted August 11, 2010 luckily i know a script that will, a bit bigger! but it works.It certainly does work. I will give credit where it is due. I don't know your name but I will have a comment with your user name and a listing for this thread in my eBook. I truly appreciate your time. What I appreciate almost as much is that you didn't say things like "you shouldn't do that", etc. etc. Instead, you tried to understand what I was trying to do and you worked to solve the problem for me. I don't mind trying to look things up for myself. I had just hit a brick wall and gotten more than a few comments from others on other forums that were not as helpful.Kindest regards,Linda Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.