You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more
So - due to the weird design of this application, the main window opens another in which one does one's work. The 'logout' button simply closes the work window and redirects the original one. However if you close the original window manually the work window keeps working, then when you click the aforementioned logout button you get a javascript error of course. The logout button tries to call a javascript function in the parent window.
So if the main window has been closed all I want to do is close the work window when the user clicks logout. However that does not seem to be possible. Looks like only the parent window can close the child window - it can't close itself. Is that right?
? Do you want the child to call Parent.window.close() or something similar?
Javascript:alert("rusty");
🙂
No. Currently it calls a function in the parent that closes the child. However if the parent's been closed, then that won't work.
I call window.close() in the child window and it does nothing. No error either. Same in IE8 and Chrome. So I am thinking it's meant to be that way - a child can't close itself.
window.close() should work in the child regardless, just tried it on one of my pages. Are you trying to call anything before that that is possibly blowing out the javascript (like trying to hit the parent) before the call?
Er... let's see.
function logofftr() {
if (confirm('Do you want to logout?'))
{
if (wlWindow && !wlWindow.closed) {
wlWindow.close();
}
if (parent.opener && !parent.opener.closed) {
parent.opener.logofftr();
} else {
window.close();
}
return false;
}
else
{
return false;
}
}
wlWindow is not significant - that's another window opened by this that I don't care about. opener.logofftr() just calls a function in the parent that closes the child window...
I no nothing about programming but should the last five squigly brackes be closed, closed, open, closed, closed? they seem to be open then closed round certain sections of code above
No. The brackets are ok 🙂
as i said i know nothing, good luck in gertting it sorted.
What happens if you stick "window.close();" as the first line of the function?
So the parent is closed when this is called and you just want the child to close? Is there an error being caught on checking if (parent.opener && !parent.opener.closed) as the parent is null, which then prevents the window.close in the else from executing?
I'm not sure I can help, but I'm vaguely interested 🙂
Am sure you can close a child window - been a while since I last tried though. Does it work if you take out everything apart from window.close()?
IE/Chrome Developer tools and Firebug all have javascript debuggers, so you should have fixed this by now! 😆
Had the debugger out. It just executes the line and nothing happens.
Which line, the last window.close()?
Is wlWindow a variable that is declared in scope etc (not that javascript always cares about this).
It's not the wlWindow I care about - that's another child window.
It's the window in which this very JS is running.
It didn't work when I removed the entire thing apart from window.close either.
Security setting?
[s]Quite possibly, yes.[/s]
Actually I don't know but this works for me
function CloseWindow() {
window.close();
}
and then IE pops up a message "The webpage you are viewing is trying to close the window. Do you want to close this window?". That would suggest that IE has got the final say. And there are a bunch of IE settings that deal with Javascript
Ask on StackOverflow, you'll probably get an answer for this within minutes 🙂
Does the child window have another name from when it was opened?
myWindow=window.open('','','width=200,height=100');
myWindow.close ();
Or try using "self.close()"
My knowledge is probably as good as rusty Mac but I am learning slowly
Do you really need all those spurious curly braces for the one-line statements? without any indentation they just serve to confuse and they also take up vertical space pointlessly.
The only bug I have ever seen that is related to curly braces and if statements was actually the other way round than you would normally think, as in someone had:
if (a)
{
<indent>blah1
}
else
{
<indent>blah2
}
<indent>blah3
if they only used braces for when it was a multi-line condition it would be obvious what was wrong.
TG, why start a coding standards argument?! If the last line wasn't indented your example code would be very readable. It isn't Molgrips problem anyway.
MG, if I don't at least do var wlWindow; in the child window I get this message:
'wlWindow' is undefined
And everything stops. Otherwise though, it works for me.
I no nothing about programming but should the last five squigly brackes be closed, closed, open, closed, closed? they seem to be open then closed round certain sections of code above
because someone was confused - proving my point.
The guy didn't know anything about programming though! Also he'd be able to read it easier if the indenting was kept when Molgrips pasted the code.
[url= http://stackoverflow.com/questions/254864/would-it-be-bad-form-to-put-braces-on-the-same-line-as-the-statement-for-single-l ]Dorky discussion about closing braces etc etc etc (etc)[/url]
I've got to get back to my real job of putting curly braces in the wrong place 😛
there is no argument about where to place braces - Java, Javascript, C#, C++ are all C-based languages so the answer is to use the same style as the inventors of C - easy.
code layout is a legitimate point of discussion as it has been shown that if an experienced programmer is shown code in a format that he is not used to then he is not much better than a junior programmer at spotting issues with it.
Hence the correct format is the one most people use, unless it is anything suggested by microsoft.
normally that would be in the same style as the inventors of the language, so K&R for C, Stroustrup for C++, Gosling for Java, etc.
The answer is to put the whole thing into a load of nested ternary operators thus not needing any curly braces.
The answer is to put the whole thing into a load of nested ternary operators thus not needing any curly braces.
and that would only be the answer if that was the idiomatic way of programming in that language.
That is why Perl is so poor, perl programmers delight in that tmtowtdi rubbish.
I was only joking! I write a lot of python, I indent everything now.
function logofftr() {
if (confirm('Do you want to logout?'))
{
if (wlWindow && !wlWindow.closed)
wlWindow.close();
if (parent.opener && !parent.opener.closed)
parent.opener.logofftr();
else
window.close();
return false;
}
else
return false;
Fixed for TG and Rusty Mac! Now can someone please help Molgrips?
p.s. Spot the change I inadvertently introduced.
not sure I can see it apart from losing the last brace.
why does the function always return false - just because you have to return something with a function? (not a javascript programmer)
otherwise I would have thought:
[code]
function logofftr()
{
....if (confirm('Do you want to logout?'))
....{
........if (wlWindow && !wlWindow.closed)
............wlWindow.close();
........if (parent.opener && !parent.opener.closed)
............parent.opener.logofftr();
........else
............window.close();
........return true;
....}
....return false;
}
[/code]
(where . = space 'cos I don't know how to BBCode it)
I assume that the parent window doesn't have the same definition of logofftr and is asking for confirmation as well?
MG, if I don't at least do var wlWindow; in the child window I get this message:'wlWindow' is undefined
Yeah this is only a small part of a script, wlWindow is defined elsewhere.
If you guys get a dialog box then I'm thinking it's security settings.
Wo wo wo wo wo what am I being dragged into now, I don't do programming. Just. Remembered from uni that formatting was important to it running smoothly and additional symbols can close other parts of the program un intentionally and some times these things are over looked by someone looking for a more complex problem. Hopefully mol will have the problem sorted now any way