GWT 后退按钮浏览器

发布于 2024-09-01 01:09:03 字数 212 浏览 4 评论 0原文

例如当前页面是 www.google.com。 但我在地址栏中输入了不同的网站地址并单击。本站已全面 GWT 代码。

但我喜欢回到 www.google.com 的上一页。 所以我点击了浏览器的后退按钮。但是如何从当前获取后退按钮的事件 GWT 代码。我可以在当前页面的 GWT 中设置任何后退按钮事件处理程序吗? 一个通知我后退按钮被按下的警报。

GWT 有什么解决方案吗?

For example current page is www.google.com.
But I typed a different website address in address bar and clicked. This site has fully
GWT code.

But I like to back to the previous page of www.google.com.
So I clicked back button of browser.but how can I get event of back button from current
GWT code. Can I set any backbutton event handler in GWT of current page?
One which notifies an alert to me that back button was pressed.

Is there any solution from GWT?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

吃不饱 2024-09-08 01:09:03

伊戈尔和亚历克斯+1。如果您想使用 ClosingHandler,这里有一些您可以使用的代码:

    Window.addWindowClosingHandler(new Window.ClosingHandler() {

        @Override
        public void onWindowClosing(final ClosingEvent event) {
            event.setMessage("Don't you think my site is awesome?");
        }
    });

来自 ClosingHandler.onWindowClosing() 的 Javadoc 的一些信息:

 /* Fired just before the browser window closes or navigates to a different
  * site. No user-interface may be displayed during shutdown. */

+1 to Igor and Alex. Here's some code you can use, if you want to use the ClosingHandler:

    Window.addWindowClosingHandler(new Window.ClosingHandler() {

        @Override
        public void onWindowClosing(final ClosingEvent event) {
            event.setMessage("Don't you think my site is awesome?");
        }
    });

Some info from the Javadoc of ClosingHandler.onWindowClosing():

 /* Fired just before the browser window closes or navigates to a different
  * site. No user-interface may be displayed during shutdown. */
往日 2024-09-08 01:09:03

<代码>Window.ClosingEvent

在浏览器窗口之前触发
关闭或导航到不同的
网站。

另一个选项是 History.addValueChangeHandler,监听浏览器历史堆栈中的更改(请参阅 文档了解更多信息)。

There's Window.ClosingEvent:

Fired just before the browser window
closes or navigates to a different
site.

The other option is History.addValueChangeHandler, which listens for changes in the browser's history stack (see the docs for more info).

叫思念不要吵 2024-09-08 01:09:03

您可以实现 HistoryListener 接口:您的类的方法 onHistoryChanged 将在每次点击时调用(带有 String 标记)后退和前进按钮。然后,您可以与 History 类,它有一个 back() 静态方法来“返回”。然而,我并不完全确定它是否会一直返回到 GWT 启动之前(但它确实值得尝试;-)。

You can implement the HistoryListener interface: your class's method onHistoryChanged will be called (with a String token) on every click to the back and forward buttons. You can then interact with the History class, which has e.g. a back() static method to "go back". However, I'm not entirely sure if it goes back all the way to before GWT started (but it's sure worth trying;-).

余生一个溪 2024-09-08 01:09:03

试试这个,它会起作用

Event.addNativePreviewHandler(new Event.NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(final NativePreviewEvent event) {
            if (event.getTypeInt() == Event.ONKEYDOWN) {
                if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_BACKSPACE) {
                    Element element = Element.as(event.getNativeEvent().getEventTarget());

                    String tagName = element.getTagName();

                    System.out.println(tagName);

                    // Add checks for other input controls
                    if (!tagName.equalsIgnoreCase("INPUT") 
                                 && !tagName.equalsIgnoreCase("TEXTAREA")) {

                        boolean result = Window.confirm("Are you sure?");
                        if (!result) {
                            event.cancel();
                        }
                    }
                }
            }
        }
    });

try this it will work

Event.addNativePreviewHandler(new Event.NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(final NativePreviewEvent event) {
            if (event.getTypeInt() == Event.ONKEYDOWN) {
                if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_BACKSPACE) {
                    Element element = Element.as(event.getNativeEvent().getEventTarget());

                    String tagName = element.getTagName();

                    System.out.println(tagName);

                    // Add checks for other input controls
                    if (!tagName.equalsIgnoreCase("INPUT") 
                                 && !tagName.equalsIgnoreCase("TEXTAREA")) {

                        boolean result = Window.confirm("Are you sure?");
                        if (!result) {
                            event.cancel();
                        }
                    }
                }
            }
        }
    });
栀梦 2024-09-08 01:09:03

你也可以使用这个本机代码

 public native void call()/*-{

    $wnd.onkeydown = GetChar;

     function GetChar (event)
     {
        var key = event.keyCode;

        var bb = event.target.nodeName;

        if(key==8 && bb=="BODY")//checking keyCode of key for backspace
                {
                    var x= window.confirm("Are you sureyou want to leave the page");

                    if (x==true)
                            {
                                window.history.back();
                            }
                    else if(x==false)
                            {

                                return false;
                            }
                }
        }                   
}-*/;

you also can use this native code

 public native void call()/*-{

    $wnd.onkeydown = GetChar;

     function GetChar (event)
     {
        var key = event.keyCode;

        var bb = event.target.nodeName;

        if(key==8 && bb=="BODY")//checking keyCode of key for backspace
                {
                    var x= window.confirm("Are you sureyou want to leave the page");

                    if (x==true)
                            {
                                window.history.back();
                            }
                    else if(x==false)
                            {

                                return false;
                            }
                }
        }                   
}-*/;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文