Tuesday, July 1, 2008

Disable Browser Back Button in OAF

Hi all,
These days I am so muh busy with SOA, ADF and Bpel projects that I do not get time to write articles. But recently helped a friend in old team for fixing browser back button in one of his OAF transaction pages which was creating error in his page.

Basically a small trick used in various J2EE projects in javascript helps to sort of nullify the browser back button in oaf page. This is what you need to do,
Put following code in process request of OAF page :
OABodyBean bodyBean = (OABodyBean) OAPageContext.getRootWebBean();
String javaS = “javascript:window.history.forward(1);”;

Actually window.history.forward(1) would push the current page ahead in the "visited pages history". A negative number like -1 would restore the previous visited page from browser's cache. Zero is relative to the current (displayed) page. Positive numbers would navigate forward.
If the page number (positive) does not exist in history, your browser will create an entry "copying" the current page to it and setting it as the current entry, so that the previous and actual are the same.

Using window.history.forward(1) does not disable "Back button". The button will work BUT as this script runs on page loading, it will send you "ahead" the history, which stored URL (or page) is the same. So it works like a "Refresh" button, without actually refreshing content from server, but just restoring from cache.
Hope this helps all.


nguma said...

window.history.forward(1) is bad syntax as forward() method has no param.
Your tip works only in MSIE.
This works in all browsers :
[script type="text/javascript"]
function noBack(){window.history.forward();}
[body onload="noBack();" onpageshow="if(event.persisted)noBack();" onunload=""]
Please replace all "<" and "]" by "<" and ">".

vettrivelou said...

i am getting an error
"non-static method getRootWebBean() cannot be referenced from a static context.

vettrivelou said...

I am able to fix that error.. But back button is still taking me to previous page


Santhosh kumar said...


can you please tell how you fix that non-static method getRootWebBean() error

Santhosh Kumar. K