Viewing 29 posts - 1 through 29 (of 29 total)
  • Bloomin' javascript!
  • molgrips
    Free Member

    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?

    toby1
    Full Member

    ? Do you want the child to call Parent.window.close() or something similar?

    Javascript:alert(“rusty”);

    🙂

    molgrips
    Free Member

    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.

    breatheeasy
    Free Member

    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?

    molgrips
    Free Member

    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…

    RustyMac
    Full Member

    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

    molgrips
    Free Member

    No. The brackets are ok 🙂

    RustyMac
    Full Member

    as i said i know nothing, good luck in gertting it sorted.

    mogrim
    Full Member

    What happens if you stick “window.close();” as the first line of the function?

    toby1
    Full Member

    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 🙂

    thebunk
    Full Member

    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! 😆

    molgrips
    Free Member

    Had the debugger out. It just executes the line and nothing happens.

    thebunk
    Full Member

    Which line, the last window.close()?

    Is wlWindow a variable that is declared in scope etc (not that javascript always cares about this).

    molgrips
    Free Member

    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?

    ourkidsam
    Free Member

    Quite possibly, yes.

    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

    chvck
    Free Member

    Ask on StackOverflow, you’ll probably get an answer for this within minutes 🙂

    muddy_bum
    Free Member

    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

    TurnerGuy
    Free Member

    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.

    thebunk
    Full Member

    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.

    TurnerGuy
    Free Member

    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.

    thebunk
    Full Member

    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.

    Dorky discussion about closing braces etc etc etc (etc)

    I’ve got to get back to my real job of putting curly braces in the wrong place 😛

    TurnerGuy
    Free Member

    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.

    chvck
    Free Member

    The answer is to put the whole thing into a load of nested ternary operators thus not needing any curly braces.

    TurnerGuy
    Free Member

    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.

    chvck
    Free Member

    I was only joking! I write a lot of python, I indent everything now.

    thebunk
    Full Member

    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.

    TurnerGuy
    Free Member

    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:


    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;
    }

    (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?

    molgrips
    Free Member

    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.

    RustyMac
    Full Member

    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

Viewing 29 posts - 1 through 29 (of 29 total)

The topic ‘Bloomin' javascript!’ is closed to new replies.