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

Can anyone explain why this doesn't work?

P: n/a
I have an application that uses a window.open() to open it's own main window
where all my programs takes place. I use a timeout so if nothing goes on for
15 minutes the document below is called. To log in again all the users have
to do is to click the link in the lower part of the window. This causes the
login window to show up again. The problem arise if the window that opened
this window has been closed in the meantime. To deal with this and avoid the
top.window.opener is null or not an object error I made the startLogin
function. When the original top window has been closed the alert shows up
fine and thereby indicates that the program has reached that far, but the
document.location stuff doesn't work. Nothing happens. As you can see, I've
tried several different versions (and others too), but none of them seem to
work. Can anyone tell me what I'm doing wrong?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<title>Logged Out</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="Styles/StylesMenu.css" rel="stylesheet" type="text/css">
<script type=text/javascript>
function startLogin(){
if (top.window.opener){
top.window.opener.location="Default.htm";
top.window.close();
}
else {
alert("It get's to this point and then nothing more happens!");
self.document.location="Default.htm";
self.document.location.href("Default.htm");
document.location="Default.htm";
location="Default.htm";
}
}
</script>

</head>

<body onload="javascript:window.status='The system logged you out!'">
<form>
<table align="center" border="0">
<tr>
<td><div align="center"><img border="6" src="images/Trwww2.gif"
ALIGN="MIDDLE"></div>
</td>
</tr>
</table>
<h1 align="center">You are logged out!</h1>
</p>
<div align="center"><font size="2"><a href="javascript:void(0);"
onclick="startLogin();">Log in again</a></font></div>
</form>
</body>
</html>

Thanks for any help!
iv**@tda.no
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <pj******************@news2.e.nsc.no>, iv**@tda.no enlightened us
with...
Can anyone tell me what I'm doing wrong?
Classic mistake.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Um, quirks mode?
Just an aside. Nothing to do with the error.
else {
alert("It get's to this point and then nothing more happens!");
self.document.location="Default.htm";


You just changed the location of the current document. Therefore, no more
script is present to execute (unless there's some in default.htm), as it got
wiped out by the new page.
--
--
~kaeli~
Can you be a closet claustrophobic?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
else {
alert("It get's to this point and then nothing more >>happens!");
self.document.location="Default.htm";
You just changed the location of the current document. >Therefore, no morescript is present to execute (unless there's some in >default.htm), as it gotwiped out by the new page.


but although I set self.document.location to Default.htm, Default.htm
never shows up in the browser! Shouldn't the current window at least
show Default.htm? It doesn't. That is the problem I wanted help with ;-)

Brgds
Iv**@tda.no

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3

P: n/a
In article <41**********************@news.newsgroups.ws>, iv**@tda.no
enlightened us with...
else {
alert("It get's to this point and then nothing more >>happens!");
self.document.location="Default.htm";

You just changed the location of the current document. >Therefore, no

more
script is present to execute (unless there's some in >default.htm), as

it got
wiped out by the new page.


but although I set self.document.location to Default.htm, Default.htm
never shows up in the browser! Shouldn't the current window at least
show Default.htm? It doesn't. That is the problem I wanted help with ;-)


Then the line is erroring out, more than likely.

Try using one of these instead.
Why are you using top.window.opener? Is this a frameset or iframe? If not,
you can probably ditch top for cleaner code. 'top' is a window object. I
don't see the need for 'top.window'. Either use top.opener or just opener.

I don't have your whole code, so check these two versions out and use the one
that works for you.

#1:
Assumes the window running this is a frameset or in an iframe:
if (top.opener){
top.opener.location="Default.htm";
top.close();
}
else {
top.document.location.href = "Default.htm"; /* use if entire frameset
should go to default */
// self.document.location.href = "Default.htm"; /* use this one if only the
current doc should go */
}

'top' would reference the upper-most window object. If a multi-layer
frameset, you may need 'parent' instead.

#2:
Assumes this code is running from a popup that is not part of a frameset:
if (self.opener){
self.opener.location="Default.htm";
self.close();
}
else {
self.document.location.href = "Default.htm";
}

Location is technically an object. href is the property to set.

Also, this code is redundant.
<body onload="javascript:window.status='The system logged you out!'">

onload is by its very nature a script event.
<body onload="window.status='The system logged you out!'">
Note that some browsers allow users to disable changing of status bar text.

Also, this isn't cool, either.
<div align="center"><font size="2"><a href="javascript:void(0);"
onclick="startLogin();">Log in again</a></font></div>

An anchor is just that - an anchor that when clicked goes to some other
document or a place in the current document (or it names a place in a
document). In newer browsers, there is just no need to pretend it's a link
when it's really more of a button (it doesn't go anywhere - it calls a script
function). NN4 didn't support div onClick, so people got used to using
anchors to do things that they really weren't intended to do.
If you want to really do it the right way, you use a real button and style it
with CSS to look like whatever you want (you can make it look like a text
link if you desire).

So, if this is an internet app and you don't know what your users have, use:
<div align="center"><font size="2"><a href="someNonJSpage.htm"
onclick="startLogin();return false;">Log in again</a></font></div>

If this is intranet and you have to support NN4, you can use the above or
use:
<div align="center"><font size="2"><a href="#"
onclick="startLogin();return false;">Log in again</a></font></div>

The 'return false' prevents the link from being followed when the function is
done being run.

If this is intranet and your users have modern browsers, NN6+/IE5
+/Mozilla/Opera6+, use:
<div align="center"><font size="2"><div onclick="startLogin();">Log in again
</div></font></div>
(name and style div as desired)

or:

<div align="center"><input type="button" value="Log In Again"
onClick="startLogin()"></div>
(again, style as desired)

HTH

--
--
~kaeli~
You can't have everything. Where would you put it?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4

P: n/a
Thanks a lot for taking the time to help me!

IVer
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.