从一个类导航到另一个创建的历史记录时,我有两个类。现在,我想通过确认用户是否要离开页面来提示用户。直到现在,我尝试在 gwt
中使用 Window.closingHandler()
但它不适用于退格按钮和浏览器后退按钮,它仅适用于关闭整个浏览器或使用交叉的特定页面。它还在重新加载。
我也试过 Javascript,使用 onbeforeunload()
效果很好。
这是我使用的代码。
JavaScript:
window.onbeforeunload = function () {
return "Are you sure you wish to leave this delightful page?";
}
还有gwt中的其他代码:
Window.addWindowClosingHandler(new Window.ClosingHandler() {
public void onWindowClosing(ClosingEvent event) {
event.setMessage("Do you wanna close?");
System.out.println("Closing...");
}
});
我希望它在 gwt
中完成。
最佳答案
我在 JSNI 中得到了这个,但它在浏览器后退按钮中也不起作用..
public native void call()/*-{
$wnd.onkeypress = GetChar;
function GetChar (event)
{
var key = event.keyCode;
var bb = event.target.nodeName;
if(key==8 && bb=="BODY")
{
var x= window.confirm("Are you sureyou want to leave the page");
if (x==true)
{
window.history.back();
}
else if(x==false)
{
return false;
}
}
}
}-*/;
关于java - 在 gwt 中提示用户退格键和浏览器后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23291882/