473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can anyone explain why this doesn't work?

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
4 9488
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
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
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
Thanks a lot for taking the time to help me!

IVer
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bo Wisén | last post by:
Hi, A project in VB6 recently worked without any problems but now it's complaining when I try to use 'Right$'. In immediate mode, when I'm typing 'print left$("123456",2)' I get the correct...
1
by: Jinlin | last post by:
I found a interesting problem in C# and couldn't explain it. The code to reproduce it is very simple: 1. Create a windows application in C#. 2. Listen to the activated event on the default form...
13
by: C++fan | last post by:
The following code is for list operation. But I can not understand. Could anyone explain the code for me? /* * List definitions. */ #define LIST_HEAD(name, type) struct name { type...
3
by: Robert A. van Ginkel | last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I can see if all the data is on the other side of the connection. I got as answer that I should use the blocking property. I...
5
by: tony | last post by:
I'm using PHP 5 on Win-98 command line (ie no web server involved) I'm processing a large csv file and when I loop through it I can process around 275 records per second. However at around...
2
by: PleegWat | last post by:
Hi, I'm using this function: function die_quietly( $text='', $title='', $file='', $line='', $sql='' ) { global $wowdb, $roster_conf, $wordings, $roster_menu; // die_quitely died quietly...
6
by: MZ | last post by:
Hello! The following js code doesn`t work fine on Firefox and I don`t know why. I have table with 30 rows and on IE I click once on analyse button and it fills my cells automaticaly, but when I...
1
Eclipse
by: Eclipse | last post by:
G'day all Can anyone explain the difference in the results to me as I don't understand why specifying the directory name in two different ways could give a different answer. In CODE 1 below i...
1
by: windscar | last post by:
Hello Everybody! I am a beginner that try to learn C++ programming. I work in Linux Ubuntu Karmic Koala (9.10) environment. I got a problem with getchar(). The function works well in a simple...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.