You are not allowed to modify the window.history entrys. If you try to set window.history.length most browsers will throw an exception.
But you can do a more smooth thing with onbeforeunload like
window.onbeforeunload = function(){
return "are you sure?";
};
that will fire a confirmation box when the user trys to leave the current page (including, history back/forward).