admin管理员组文章数量:1312658
My webpage runs a javascript function when the page is loaded. However, I don't want the function to run if the user es back to this page using the back button. How can I prevent this using javascript?
$(document).ready(function(){
// Do not run this function if the user has arrived here using the back button
RefreshThePage();
});
My webpage runs a javascript function when the page is loaded. However, I don't want the function to run if the user es back to this page using the back button. How can I prevent this using javascript?
$(document).ready(function(){
// Do not run this function if the user has arrived here using the back button
RefreshThePage();
});
Share
Improve this question
asked Mar 23, 2010 at 9:20
TomTom
1,0574 gold badges15 silver badges27 bronze badges
3
- possible duplicate of stackoverflow./questions/55871/… – T.J. Crowder Commented Mar 30, 2010 at 14:35
- Duplicate: stackoverflow./questions/55871/… At least one better answer here, though, question should be merged but not deleted. – T.J. Crowder Commented Mar 30, 2010 at 14:36
- I have same problem right now, can you share how did you solve this problem? – Agung Setiawan Commented Sep 1, 2014 at 15:10
4 Answers
Reset to default 4I'd have thought that using cookies is the easiest way to do this
I think studying the way Struts handles duplicate form submissions could help you.
Some links:
http://www.techfaq360./tutorial/multiclick.jsp
http://www.java-samples./showtutorial.php?tutorialid=582
http://www.xinotes/notes/note/369/
Track when user hits back button on the browser
There are multiple ways of doing it, though some will only work in certain browsers. One that I know off the top of my head is to embed a tiny near-invisible iframe on the page. When the user hits the back button the iframe is navigated back which you can detect and then update your page. Here is another solution.
You might also want to go view source on something like gmail and see how they do it.
Here's a library for the sort of thing you're looking for by the way
The event object offers you to get the key code. so basically you register an eventlistener onKeyDown. Use the received event. if the keycode matches the key you like continue with your function.
document getElementById('elementId').onKeyDown = checkKey();
function checkKey(event) {
if (event.keyCode === keyCode) then . . .
}
play around with alert(event.keyCode); to find the right one.
本文标签: javascriptDetect if the user has used the back buttonStack Overflow
版权声明:本文标题:javascript - Detect if the user has used the back button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741914398a2404639.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论