SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to clear browsers' cache with javascript?

    Dear All,

    how to clear browsers' cache with javascript? .. so users will unable to go to previous page after they logged out..

    I tried to add <meta http-equiv="Pragma" content="no-cache"> on head section of my page1.jsp .. but it does not work


    Code:
    <&#37;@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    
    <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
    
    <html>
        <head>
            <meta http-equiv="pragma" content="no-cache" />
            <link rel="stylesheet" type="text/css" href="stylesheet.css">
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Login Success</title>
        </head>
        <body>
            <h1>Congratulations!</h1>
            <p>You have successfully logged in.</p>
            <p>Your name is: <bean:write name="LoginForm" property="name" />.</p>
            <p>Your email address is: <bean:write name="LoginForm" property="email" />.</p>
            <p></p>
            <a href="Logout.do">Logout</a>
        </body>
    </html>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,712
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    If you don't want them to be able to go back to the previous page, you can achieve that not with javascript, but with a server-side redirect that redirects the from the previous page to the new page.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict bronze trophy AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    298
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you replace the anchor with an onclick handler you can use location.replace, which replaces the current page in history with the new page. The following script lets you save or remove the history.

    <html>

    <head>

    <style type="text/css">
    <!--
    body { font-family:arial; font-size:14px; color:#000080; font-weight:bold; }
    .curs { cursor: pointer; }
    -->
    </style>
    </head>

    <body>

    <p class="curs" onclick="location.href='logout.htm'">Logout leaving history</p>
    <p class="curs" onclick="location.replace('logout.htm')">Logout removing history</p>

    </body>

    </html>

  4. #4
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't use javascript for something like that.

    It wouldn't work for users with javascript turned off for any reason.

    I to would do it server side.

    btw - if the user's session is properly terminated when they log out, it shouldn't matter if they immediately go back to the previous page because they will then get a "Session Expired" (or something similar) error message in their browser by default.

  5. #5
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Javascript for it is some of the worst advice I've seen in a while... especially since for what you asked it wouldn't even work.

    What you are looking to do is, as Kalon said, best handled server-side, specifically using HTTP response headers.

    If you are using PHP, that's what the 'header' function is for.

    http://php.net/manual/en/function.header.php

    See their second example:

    Code:
    <?php
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    ?>
    Should work flawless every time. In addition to that if this is a form/submit you don't want repeating, I would store a semi-random hash in a database md5(random.IP Addy.timestamp) and in a hidden input on the form on the page you don't want them going back to. When they submit the first time, delete it from the database. If the hash is submitted and isn't in the database, you'll know the form was submitted more than once.

  6. #6
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Oh, BTW -- you have to send headers BEFORE any markup is sent. Just figured I'd point that out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •