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

    1. <tfoot id='iDpfk'></tfoot>

        <legend id='iDpfk'><style id='iDpfk'><dir id='iDpfk'><q id='iDpfk'></q></dir></style></legend>

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

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

        当用户尝试离开页面而不保存时创建确认 JavaScript

        Create confirm JavaScript for when users try to leave page without saving(当用户尝试离开页面而不保存时创建确认 JavaScript)
        • <bdo id='GHPN6'></bdo><ul id='GHPN6'></ul>

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

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

              <tbody id='GHPN6'></tbody>

                • 本文介绍了当用户尝试离开页面而不保存时创建确认 JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试这样做,以便如果用户对页面进行更改然后尝试离开页面而不保存,则会出现一条带有确定"按钮(没有取消"按钮)的弹出消息.单击确定"按钮,关闭消息.用户必须单击保存"按钮,否则他们将继续收到消息,禁止他们离开页面,直到单击保存"按钮.离开页面,我的意思是阻止他们导航到站点内的另一个选项卡或菜单项......如果他们点击页面上的任何其他链接,它会给他们弹出窗口.他们可以随时离开他们的网站.

                  I am trying to make it so that if a user makes changes to a page and then tries to leave the page without saving, a popup message will appear with an "OK" button (no "Cancel" button). Clicking the "OK" button, closes the message. The user must click the "Save" button or they will keep getting the message, prohibiting them from leaving the page until the "Save" button is clicked. By leave the page, I mean keeping them from navigating to another tab or menu item within the site...if they click any other link on the page, it would give them the popup. They can leave they site at anytime.

                  我想我需要 JavaScript 模式对话框来摆脱取消"按钮,但对实现有点不确定.

                  I am thinking I need JavaScript modal dialog to get rid of the Cancel button but am a bit uncertain of the implementation.

                  目前,我正在使用 r = Confirm(见下文),但它有一个取消按钮,并且如果用户单击确定",它可以选择离开页面.我不希望他们在不点击保存"按钮的情况下离开页面,否则他们将不得不关闭整个窗口.

                  Currently, I am using r = confirm (see below) but it has the cancel button plus it gives the option for users to leave the page if they click "OK". I do not want them to be able to leave the page without clicking the "Save" button or they would have to close the entire window.

                  非常感谢任何帮助/解释,因为我对此很陌生.谢谢.

                  Any help/explanation is very much appreciated as I am very new to this. Thank you.

                  if (typeof unsaved != 'undefined') {
                  if (unsaved == true) {
                  var r = confirm("Please click Update. Unsaved changes will be lost.");
                  if (r == false) {
                       saveNeeded = "true";
                       }
                       else { saveNeeded = "false"; }
                   }
                  }
                  

                  推荐答案

                  看看onBeforeUnload.

                  您无法强制用户留在网站上,但是当用户尝试关闭窗口时,它会提供一个带有离开"和停留"按钮的弹出窗口.所有主要的网络浏览器都允许用户随意离开任何网页,你能做的最多就是警告他们.onBeforeUnload 可能是您将实现的最佳跨浏览器解决方案,让用户有机会留在网站上并在离开前保存他们的更改.

                  You won't be able to force a user to stay on the website, however it will provide a pop up window with the 'Leave' and 'Stay' buttons when they attempt to close the window. All major web browsers allow the user to leave any webpage at will, and the most you can do is warn them. onBeforeUnload is probably the best cross-browser solution you will achieve to give users a chance to stay on the site and save their changes before leaving.

                  <script language="JavaScript">
                      window.onbeforeunload = confirmExit;
                      function confirmExit() {
                          return "Please click Update. Unsaved changes will be lost.";
                      }
                  </script>
                  

                  尝试将用户锁定到您的网站而不选择离开是非常糟糕的做法,这就是任何主要网络浏览器都不支持的原因.如果您必须强迫用户做某事非常重要(并且您有权作为公司等),您应该使用另一个平台或为用户的网络浏览器编写自定义插件.但对于一般用途,您不能锁定他们的浏览器.

                  It would be very bad practice to attempt to lock a user to your website without an option of leaving, which is why it is not supported by any major web browsers. If it is so important that you MUST force the user to do something (and you have the right to as a company or such), you should use another platform or write a custom plugin to the user's web browser. But for general use, you can't lock their browser.

                  这篇关于当用户尝试离开页面而不保存时创建确认 JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                  How to upload image into HTML5 canvas(如何将图像上传到 HTML5 画布中)
                  How to show a running progress bar while page is loading(如何在页面加载时显示正在运行的进度条)

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

                    1. <small id='aXVbD'></small><noframes id='aXVbD'>

                          <tbody id='aXVbD'></tbody>
                        <tfoot id='aXVbD'></tfoot>
                          <bdo id='aXVbD'></bdo><ul id='aXVbD'></ul>
                          <legend id='aXVbD'><style id='aXVbD'><dir id='aXVbD'><q id='aXVbD'></q></dir></style></legend>