Morgan Ng Morgan Ng - 3 months ago 9
HTML Question

Logout URL in same window and in same tab

I want to logout a link in the same window and in the same tab that contains the page with the link.

When I try click logout a link by using window.open, then it opens in new tab—not in the same tab in the same window and the current page will not logout unless i refresh the pages.

code:

+"<button class=\"withdraw\" onclick=\"window.open(\'/index/LogOut.html\')\">Logout</button>"

Answer

Instead of using window.open, you can set the window.location.href property which will caues the current window to navigate to the specified URL.

e.g.

<button class="withdraw" onclick="window.location.href='/index/LogOut.html'">Logout</button>

Comments