I have a website that is on a slide show and when the user presses the back button I would like it to go back to the album view not the prior and prevent page. Is there a way of doing this? thanks for any help or advice.
Is there a way using Jquery to detect the back button being pressed cross browsers
Asked Answered
jQuery Address provides strong cross-browser support for browser history and Ajax crawling:
http://www.asual.com/jquery/address
http://github.com/asual/jquery-address
Greetings
UPDATE:
you can find a good sample right here:
some code in short:
$(function() {
$('a').click(function(e) {
e.preventDefault();
$.address.value($(this).attr('href'));
});
var changecount = 0;
$.address.change(function(e) {
if (typeof e !== 'function') {
$('span').html(changecount++);
}
});
});
Did you download jquery.address-1.5 from first link I provided? –
Sustentacular
@Sustentacular yes, i included the the file right after
jquery
<script src="http://code.jquery.com/jquery.min.js"></script> <script src="jquery.address-1.5.min.js"></script> <script type="text/javascript"> $(function() { $('a').click(function(e) { e.preventDefault(); $.address.value($(this).attr('href')); }); var changecount = 0; $.address.change(function(e) { if (typeof e !== 'function') { $('span').html(changecount++); } }); }); </script>
–
Lignite @Sustentacular getting errors:
Uncaught TypeError: Cannot read property 'version' of undefined jquery.address- Uncaught TypeError: Cannot call method 'change' of undefined
–
Lignite @Sustentacular found the solution,
<script src="http://code.jquery.com/jquery-migrate-1.0.0.js"></script>
–
Lignite You should:
- Set
location.hash
when page state changes. - When
location.hash
changed by user (for example, by pressing back button) render appropriate page contents.
© 2022 - 2024 — McMap. All rights reserved.