• <small id='wynFF'></small><noframes id='wynFF'>

  • <i id='wynFF'><tr id='wynFF'><dt id='wynFF'><q id='wynFF'><span id='wynFF'><b id='wynFF'><form id='wynFF'><ins id='wynFF'></ins><ul id='wynFF'></ul><sub id='wynFF'></sub></form><legend id='wynFF'></legend><bdo id='wynFF'><pre id='wynFF'><center id='wynFF'></center></pre></bdo></b><th id='wynFF'></th></span></q></dt></tr></i><div id='wynFF'><tfoot id='wynFF'></tfoot><dl id='wynFF'><fieldset id='wynFF'></fieldset></dl></div>

        <bdo id='wynFF'></bdo><ul id='wynFF'></ul>
    1. <tfoot id='wynFF'></tfoot>

      1. <legend id='wynFF'><style id='wynFF'><dir id='wynFF'><q id='wynFF'></q></dir></style></legend>

        有什么方法可以检测用户是否按下了“留在页面

        时间:2023-09-04
            <i id='6RYvo'><tr id='6RYvo'><dt id='6RYvo'><q id='6RYvo'><span id='6RYvo'><b id='6RYvo'><form id='6RYvo'><ins id='6RYvo'></ins><ul id='6RYvo'></ul><sub id='6RYvo'></sub></form><legend id='6RYvo'></legend><bdo id='6RYvo'><pre id='6RYvo'><center id='6RYvo'></center></pre></bdo></b><th id='6RYvo'></th></span></q></dt></tr></i><div id='6RYvo'><tfoot id='6RYvo'></tfoot><dl id='6RYvo'><fieldset id='6RYvo'></fieldset></dl></div>

            <small id='6RYvo'></small><noframes id='6RYvo'>

          • <legend id='6RYvo'><style id='6RYvo'><dir id='6RYvo'><q id='6RYvo'></q></dir></style></legend>
                <tbody id='6RYvo'></tbody>

              <tfoot id='6RYvo'></tfoot>
                  <bdo id='6RYvo'></bdo><ul id='6RYvo'></ul>
                • 本文介绍了有什么方法可以检测用户是否按下了“留在页面上"?或“离开页面"在 beforeunload 事件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有什么方法可以在以下代码中检测到用户点击了离开页面"或留在页面上"按钮?

                  Is there any way that I could detect in the following code that either user clicked "leave page" or "stay on page" button ?

                  $(window).on('beforeunload', function (){
                      return "You save some unsaved data, Do you want to leave?";
                  });
                  

                  推荐答案

                  通过一些技巧,您至少可以确定用户是否留下.
                  如果用户离开了页面,那么您无能为力:

                  With a few hacks you can at least determine if the user stayed.
                  If the user left the page, there's not much you can do about that :

                  var timeout;
                  
                  $(window).on('beforeunload', function (){
                      timeout = setTimeout(function() {
                          // user stayed, do stuff here
                      }, 1000);
                      return "You save some unsaved data, Do you want to leave?";
                  });
                  

                  FIDDLE

                  这篇关于有什么方法可以检测用户是否按下了“留在页面上"?或“离开页面"在 beforeunload 事件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用纯 JavaScript 获取事件的选择元素值 下一篇:不将其他绑定函数覆盖到 window.onresize 的最佳做法

                  相关文章

                  最新文章

                  <tfoot id='o0Suh'></tfoot>

                  <small id='o0Suh'></small><noframes id='o0Suh'>

                    <bdo id='o0Suh'></bdo><ul id='o0Suh'></ul>

                      <legend id='o0Suh'><style id='o0Suh'><dir id='o0Suh'><q id='o0Suh'></q></dir></style></legend>
                    1. <i id='o0Suh'><tr id='o0Suh'><dt id='o0Suh'><q id='o0Suh'><span id='o0Suh'><b id='o0Suh'><form id='o0Suh'><ins id='o0Suh'></ins><ul id='o0Suh'></ul><sub id='o0Suh'></sub></form><legend id='o0Suh'></legend><bdo id='o0Suh'><pre id='o0Suh'><center id='o0Suh'></center></pre></bdo></b><th id='o0Suh'></th></span></q></dt></tr></i><div id='o0Suh'><tfoot id='o0Suh'></tfoot><dl id='o0Suh'><fieldset id='o0Suh'></fieldset></dl></div>