Alert not working in IE6 some cases

Discussion in 'Javascript' started by schieco, Apr 13, 2004.

  1. schieco

    schieco Guest

    The following code always prints the debug lines inside the
    conditional if statement before and after the alert statement when the
    session has timed out, but the alert and redirect only appear/work in
    certain situations.

    <%
    // Check for expired session
    log.debug("session ID = " + session.getAttribute("session_loginID"));

    if (session.getAttribute("session_loginID") == null)
    {
    log.debug("I am null!");
    %>
    <SCRIPT>
    alert("You have been logged out of the system.\n");

    window.top.navigate("/Login/Logout.jsp");
    </SCRIPT>
    <%
    log.debug("Where did the alert go??");
    }
    %>
     
    schieco, Apr 13, 2004
    #1
    1. Advertisements

  2. schieco

    Grant Wagner Guest

    Since you don't identify under what "certain situations" the alert() appears,
    it's impossible to determine your problem. For starters, only IE supports the
    navigate() method on the window object, so if its not working in other Web
    browsers, that's why.

    In the situations where it doesn't work, have you tried View -> Source to
    determine what the source looks like in the Web browser? It may not be what you
    expect it to be. For example, if the code above is included on every page, but
    somehow you've got it specified to be embedded between another <SCRIPT></SCRIPT>
    combination on the page, then the nested <SCRIPT><SCRIPT> tags might be the
    problem.

    Do you receive any Javascript errors or warnings in the Web browser when the
    alert() does not appear? (in IE double-click any yellow ! that appears in the
    bottom left corner, in Netscape, type "javascript:" into the Address Bar, but as
    I've already told you, navigate() won't work in Netscape, so that's the first
    thing to fix if it's not working in Netscape).

    Without more details, it's impossible to know why the alert() and the redirect
    aren't working.

    As a complete aside, the way you're doing it isn't the way to do it IMNSHO. Don't
    write out an alert() and redirect using client-side technology. Instead, redirect
    to "/Login/Logout.jsp?msg=Your+session+has+expired" using a *server-side*
    redirect.

    Then on Logout.jsp, you can do whatever you want with 'msg'. For example
    (server-side Javascript):

    <%
    var msg = Request.value("msg");
    if (msg != null) {
    Response.write('<p><strong style="color:Red;">' + msg + '</strong></p>');
    }
    %>

    or if you still want to use a client-side alert():

    <%
    var msg = Request.value("msg");
    if (msg != null) {
    Response.write('<script type="text/javascript">alert("' + msg +
    '");</script>');
    }
    %>

    But you've completely removed any dependancy on client-side technology to get you
    to Logout.jsp in the event the session times out. The user will *always* end up
    on Logout.jsp if the session expires, they just may not see your alert() if
    client-side Javascript is disabled, which is why I personally recommend using the
    <p><strong ...>...</strong></p> (or something similar) design.

    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

    * Internet Explorer DOM Reference available at:
    *
    http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-developer/upgrade_2.html
     
    Grant Wagner, Apr 21, 2004
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.