admin管理员组文章数量:1352205
I have a page that consists of two frames: one being a flash app, and one being an aspx page with a user control that contains a grid with several "add to cart" buttons. When the user clicks a button I would like to reload the whole window with a shopping cart page.
I found out how to do so here quite nicely by avoiding response.redirect, and using response.write to insert some javascript that redirects. The problem is that when the user hits the back button from the shopping cart page, the script executes again, effectively canceling out the back button. (bad usability)
So my question is, is there a way to detect if the user arrived at the page via the back button and avoid executing the script?
I have a page that consists of two frames: one being a flash app, and one being an aspx page with a user control that contains a grid with several "add to cart" buttons. When the user clicks a button I would like to reload the whole window with a shopping cart page.
I found out how to do so here quite nicely by avoiding response.redirect, and using response.write to insert some javascript that redirects. The problem is that when the user hits the back button from the shopping cart page, the script executes again, effectively canceling out the back button. (bad usability)
So my question is, is there a way to detect if the user arrived at the page via the back button and avoid executing the script?
Share Improve this question edited Jun 10, 2011 at 8:29 kazim 2,1911 gold badge19 silver badges15 bronze badges asked Apr 16, 2009 at 18:07 personaelitpersonaelit 1,6533 gold badges32 silver badges59 bronze badges 4-
1
Bad usability
and frames and a flash app in the same question? – alex Commented Apr 17, 2009 at 1:03 - And why are you using JavaScript for basic page navigation? As Andrew Duffy has mentioned, that's what the "target" attribute is for. – Calvin Commented Apr 17, 2009 at 2:47
- @alex -- Just because frames and flash are generally considered bad design, are over used, and are used incorrectly, it doesn't mean that there aren't legitimate uses for them. @Calvin -- the reason javascript is necessary for basic navigation, is because when using Response.Redirect from within my code, there is no way to specify a target since that is all handled by the client. So writing a script to the page that does the redirect for me allows me to specify a target. – personaelit Commented Apr 17, 2009 at 14:34
- I would only call them bad design because of their accessibility issues. For a start... – alex Commented Apr 18, 2009 at 4:26
3 Answers
Reset to default 11Change your javascript to replace the current URL instead of just setting it
// Creates browser history
top.location = 'http://www.stackoverflow.'
// Doesn't create browser history
top.location.replace( 'http://www.stackoverflow.' );
When the user clicks a button I would like to reload the whole window with a shopping cart page.
You should be using the Post-Redirect-Get model.
You can do this easily without using script by making the buttons submit buttons in a form with a target
attribute of _top
. Note that the target
attribute will not validate as HTML4 or XHTML.
If you are using a POST request to submit to the shopping cart (a good idea) then the Post-Redirect-Get idiom mentioned by bobince will strengthen your application further - the user won't be prompted to resubmit the form if they use the back or forward buttons to get to your shopping cart page.
本文标签: RemoveDisable javascript when using browser39s back buttonStack Overflow
版权声明:本文标题:RemoveDisable javascript when using browser's back button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743904308a2559241.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论