简体   繁体   English

如何在 HTML5 中添加自定义历史记录以防止 android 后退按钮在cordova 应用程序中显示前一个视图?

[英]How to add custom history in HTML5 to prevent android back button to display just previous view in cordova application?

I created an application with help of http://coenraets.org/blog/cordova-phonegap-3-tutorial/ .我在http://coenraets.org/blog/cordova-phonegap-3-tutorial/ 的帮助下创建了一个应用程序。 When I click on the SMS link in the Employee details view it opens native message composer because the link's is as href="sms:6170000010" , but when I click on the Android back button while message composer is opened it takes the application to previous view something like window.history.back() , but I want only to close message composer.当我单击员工详细信息视图中的 SMS 链接时,它会打开本机消息编辑器,因为该链接的href="sms:6170000010"href="sms:6170000010" ,但是当我在消息编辑器打开时单击 Android 后退按钮时,它将应用程序转到上一个查看类似window.history.back() ,但我只想关闭消息编辑器。 How can I customise my source code to only close the message composer when back button is pressed for this particular situation and for rest of the application should behave as it is?如何自定义我的源代码以仅在此特定情况下按下后退按钮时关闭消息编辑器,并且应用程序的其余部分应按原样运行?

Below is Employee details view screenshot:以下是员工详情视图截图:

在此处输入图片说明

I Fixed it using HTML5 History pushState function.This allow me to add history entry in History Array.我使用 HTML5 History pushState 函数修复了它。这允许我在 History Array 中添加历史条目。 So on android back button click will pop current(smsComposer) view from the history array and employee details view will be as it is.因此,在 android 后退按钮上,单击将从历史记录数组中弹出 current(smsComposer) 视图,而员工详细信息视图将保持原样。

<a href="sms:6170000010" onClick="modifyBrowserHistory()" >    

    function  modifyBrowserHistory(){
            window.history.pushState({page:"smsComposer"},"sms composer");

    }

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

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