是否可以onclick =" history.clear();" [英] Is it possible to onclick="history.clear();"

查看:166
本文介绍了是否可以onclick =" history.clear();"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在我的PhoneGap应用程序中实现注销按钮,这将使用户进入身份验证页面(已清除字段)。对于按钮,我使用锚定onclick事件:

I'm going to implement logout button in my PhoneGap application, which will return the user into authentication page (with cleared fields). For the button I'm using anchor with onclick event:

<script type="text/javascript">
function doLogout() {
    var backlen = history.length;
    history.go(-backlen);
    window.location.replace("index.html");
}
</script>

<a data-role="none" href="#" onclick="doLogout"></a>

但它不工作,即它只是返回到那个认证页已填充的文件,只是一步之遥。我不确定 history.clear(),因为Google搜索没有给我什么:

but it's not works, i.e. it's just returns me to that authentication page with already filled fileds, seems like just a one step back. I'm not sure for history.clear(), because googling it gave me nothing:

<a data-role="none" href="index.html" onclick="javascript:history.clear();"></a>

任何人都可以告诉我我的问题在哪里?如果有另一个解决方案来处理Logout事件在PhoneGap我会跟着它。 THanks

Could anyone advise me where is my problem? If there is another solution to handle logout event in PhoneGap I would follow it. THanks

推荐答案

history.go 的调用将被忽略,因为你会回到比历史上的项目多一步。 length 属性具有包括当前一个的项目数,因此如果历史中有例如四个项目,则只能返回三个步骤。

The call to history.go will be ignored, because you are going back one more step than there are items in the history. The length property has the number of items including the current one, so if there are for example four items in the history, you can only go back three steps.

要返回第一步,您将从长度中减去一个:

To go back to the first step, you would subtract one from the length:

history.go(-(history.length - 1));

但是,这只会带你回到起始页,如果你打开一个新的窗口页。否则会将用户返回到他使用该窗口访问的第一页。

However, that would only take you back to your start page if you opened a new window specifically for that page. Otherwise it would take the user back to the first page that he visited using that window.

没有清除历史对象的 c>方法。

There is no clear method for the history object.

=https://developer.mozilla.org/en-US/docs/DOM/window.history> https://developer.mozilla.org/zh-CN/docs/DOM/window.history

Ref: https://developer.mozilla.org/en-US/docs/DOM/window.history

浏览器历史记录属于用户,您无法从其中删除任何内容。

The browser history belongs to the user, you can't remove anything from it.

这篇关于是否可以onclick =&quot; history.clear();&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆