简体   繁体   English

从页面重定向之前询问确认

[英]Ask confirmation BEFORE Redirect from page

I have application. 我有申请。 Client side is - knockout. 客户端是-淘汰赛。

so I have page with form, and i want to ask user confirametion before he will try go to another page (in case if he changed something (this pard is ready)) 所以我有带有表单的页面,并且我想在用户尝试进入另一页面之前询问用户是否有信心(以防他更改了某些内容(此pard已准备就绪))

So routing on all website - its Sammy.js. 因此,在所有网站上路由-其Sammy.js。

I tried : Sammy JS - before 我尝试过:Sammy JS-之前

function ViewModel()
{
  Sammy.before(/.*/, function () {

        if (window.confirm('Really go to another page?')){

        }
        else{
            //DO NOTHING AND STAY IN THE SAME PAGE
            //OR SOMETHING ELSE THAT YOU WANT

            return false;
        }

     });
}

its work , but its still working for all website - and its bad. 它的工作,但它仍然适用于所有网站-而且很糟糕。 I'm not found way to disable it, so maybe I can do it without sammy??? 我找不到禁用它的方法,所以也许我可以做到不放心???

Thank you guys! 感谢大伙们!

Update: This website is SPA 更新:此网站是SPA

You can use before , but you must specify options to show the confirmation dialog only when necessary. 您可以使用before ,但是必须指定选项以仅在必要时显示确认对话框。 See the docs . 请参阅文档 You're specifying to run it for all the routes, you must specify in which routes you want it executed. 您要指定对所有路由运行它,必须指定要在其中执行的路由。 Before option only gives you information on the next route. “之前”选项仅提供有关下一条路线的信息。 If it depends on the current route, you can get it examining the current url: 如果它取决于当前路由,则可以检查当前URL:

function extractSammyUrlFrom (context)
{
  // get the hash fragment (curernt route)
  "#" + context.path.split("#")[1] ;
}

If it depends on any other thing in your page, just check it before showing the dialog. 如果它取决于页面中的任何其他内容,则在显示对话框之前先进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM