Skip to content Skip to sidebar Skip to footer

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 onc

Solution 1:

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.


There is no clear method for the history object.

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.

Solution 2:

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.

Solution 3:

If you use the onclick attribute, what goes in the quotes is an actual statement, not just the name of a function. So:

<adata-role="none"href="#"onclick="doLogout();"></a><!-- Note the (); ----------------------------^^^   -->

Also note that because you're not doing anything to prevent the default action of following the link, the browser will follow the href, which being # takes you to the top of the current page. You can prevent that (if you like) by adding a return false;:

<adata-role="none"href="#"onclick="doLogout(); return false;"></a>

I couldn't follow the second part of your question, but I'll just note that you don't need or want the javascript: on the onclick attribute in your second example. You only use that pseudo-protocol where a URI is expected (for instance, the href of an anchor). The content of onXYZ attributes is always code, not a URI.

Finally: Unless you're doing something with styling, both of those links are going to be pretty hard to click, what with being empty. :-)

Solution 4:

use: navigator.app.clearHistory();

Post a Comment for "Is It Possible To Onclick="history.clear();""