aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to call a javascript function on back button press of the brower window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to call a javascript function on back button press of the brower window" Watch "How to call a javascript function on back button press of the brower window" New topic
Author

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

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2


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.


Regards
KumarRaja

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

Could some one help me on this ?
Jagdeep Sharma
Ranch Hand

Joined: May 24, 2010
Posts: 121

Kumar Raja wrote:Could some one help me on this ?


Please show your code.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no event for back button.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call a javascript function on back button press of the brower window