Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call a javascript function on back button press of the brower window

 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi All,

We have an application where we page 1 has a submit button. As soon as this button is pressed, button would be disabled and new resulting page would be displayed. Now what is observed here is, when the user clicks the back button, page 1 is displayed back, but sometimes the submit button is still disabled.

I was asked to work on fixing this, and I also need to consider several test cases for testing this function.

So what I did for this is, on
<body>
elements onload() event, I called a function which would enable the button, if disabled by anymeans. But on clicking back button, I found that onload() event of <body> element is not called. Why is this happening? Should there be any other event to be considered for handling this.


Another usecase, which I need to consider here is restricting invalid user agents. We have some logic internally to decide if the browser is a valid one or not. For testing this, I created my own user agent using UserAgent switcher plugin and invoked the app and it worked fine.

But, say I start with a valid user agent, click submit (at this point, button is disabled) and I navigate to some other screen and at this point, I change to invalid user agent and click back button, I should still get my submit button enabled back.

Any advice on this.
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could some one help me on this ?
 
Jagdeep Sharma
Ranch Hand
Posts: 121
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kumar Raja wrote:Could some one help me on this ?


Please show your code.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no event for back button.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic