By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,212 Members | 2,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,212 IT Pros & Developers. It's quick & easy.

Alert not working in IE6 some cases

P: n/a
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??");
}
%>
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
schieco wrote:
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.


Not sure if this will help or not, does it work if you declare the
script as javascript:

<script type="text/javascript">

Jul 23 '05 #2

P: n/a
schieco wrote:
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??");
}
%>


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 <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.