简体   繁体   English

如何处理.net应用程序中的移动后退按钮

[英]how to handle mobile back button in .net application

I have .net website with responsive view. 我有响应式视图的.net网站。 when I open this website in mobile there is no way to close the menu so i want to implement when menu open and user click back button in mobile menu get closed and not to go back page and another condition is without page reloading. 当我在移动设备上打开此网站时,无法关闭菜单,因此我想在菜单打开且用户在移动菜单中单击后退按钮关闭且不返回页面时实现,而另一种情况是不重新加载页面。

You will need to add a # to the URL which you can listen for using window.onhashchange(). 您将需要在URL上添加#,以便您可以使用window.onhashchange()进行监听。 You can use location.hash to determine whether to open/close the menu. 您可以使用location.hash确定是否打开/关闭菜单。

Example: 例:

window.onhashchange = function(){
  var url = location.hash;

  switch(url)
  {
    case "#/open":
      alert('Open menu');
      break;
    default:
      alert('Close menu');
      break;

  }
}

Plunker: http://plnkr.co/edit/n2xmznbgFJCHOtBVrjjH?p=preview . 柱塞: http ://plnkr.co/edit/n2xmznbgFJCHOtBVrjjH?p=preview。 Click on the link and then press the back button 单击链接,然后按返回按钮

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

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