Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to onclick="history.clear();"

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>

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>

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

like image 901
bofanda Avatar asked Feb 17 '13 11:02

bofanda


People also ask

Can JavaScript read browser history?

To access this history stack we need to use the History object in JavaScript. History object: The history object contains the browser's history. The URLs of pages visited by the user are stored as a stack in the history object. There are multiple methods to manage/access the history object.

How to clear previous history in JavaScript?

deleteAll() Deletes all visits from the browser's history. This function triggers history. onVisitRemoved just once, with allHistory set to true and an empty urls argument.

How do I go back in history in JavaScript?

The History. back() method causes the browser to move back one page in the session history. It has the same effect as calling history.go(-1) .


1 Answers

I have never developed any PhoneGap, but in web applications you can use code below.

try window.location.replace(url);

after redirection there no way to go previous page.

like image 162
KnowGe Avatar answered Sep 27 '22 16:09

KnowGe