How can I detect on GWT client side that browser's back or forward
button is clicked? Because on click of back and forward button i want
to perform custom operation.
Thank You.
What you can is handle history changes, that occurs when user push
back and forward in the browser, but only works for links in the same
page(#anchor).
public class Dummy implements ValueChangeHandler<String>
{
public Dummy()
{
// Register ourselves with the History API.
History.addValueChangeHandler(this);
}
public void onValueChange(ValueChangeEvent<String> event)
{
// User has clicked back or forward, the event parameter has the
value itself.
}
}
Regards,
thanks for the quick reply. Is it possible that i can get it from DOM
or from javascript native code.
Maybe you can find a solution to disable the buttons.
[CODE]
//Disable F5 - Refresh
var isIE = ( navigator.userAgent.toLowerCase().indexOf("msie") !=
-1 );
function interceptKeyDown(e) {
keyCode = e.keyCode;
//F5
if ( keyCode == 116 ) {
if(isIE) {
// IE only
e.keyCode = 505;
}
return false;
}
}
function interceptKeyPress(e) {
if( !e ) {
if (window.event)
e = window.event;
else
return;
}
//NS 4, NS 6+, Mozilla 0.9+, Opera
if(typeof(e.which) == 'number') {
var keyCode = e.keyCode ? e.keyCode : e.which ? e.which :
void 0;
if(e.charCode == null || e.charCode == 0 ) {
// F5
if ( keyCode == 116 ) {
e.stopPropagation();
e.preventDefault();
}
}
}
}
function attachEventListener( obj, type, func, capture ) {
if(window.addEventListener) {
//Mozilla, Netscape, Firefox
obj.addEventListener( type, func, capture );
} else {
//IE
obj.attachEvent( 'on' + type, func );
}
}
attachEventListener(document,"keydown",interceptKeyDown,true);
attachEventListener(document,"keypress",interceptKeyPress,true);
[END-CODE]
Thanks for the reply.
If i disable the buttons how will i come to know that the back button
is clicked ?
As I wrote, maybe you can find a solution that intercept the browser
back button click.