By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,118 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,118 IT Pros & Developers. It's quick & easy.

program browser back button to redirect to different page

P: 1
Hi,
i'm designing a website with a gallery whose images contain anchors and records the location whenever a picture is viewed for example if the current picture is #pic1 then the url would be www.website.com/gallery/album1#pic1 , if i click on pic7 the url would be www.website.com/gallery/album1#pic7 and so on.. i did this so that when the url is copied and pasted the gallery would still show the last viewed image. my problem now is when i click back in my browser, the browser goes back to the previous picture not to the album, like if in the previous example if im still at pic7 the back button will take me to www.website.com/gallery/album1#pic1 instead of www.website.com/gallery
so my question is how can i program the browser back button to go back to the gallery immediately?
this is what i tried but it isnt working..
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function backToGallery()
  5. {
  6. if(window.history.previous)
  7. {window.location.href='gallery.html';}
  8. }
  9. </script>
  10. </head>
  11. <body onunload="backToGallery()">
  12. </body>
  13. </html>
  14.  
Aug 10 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.