Skip to main content
August 29, 2008
Question

Running Javascript Code to Close Window at end of page

  • August 29, 2008
  • 3 replies
  • 2143 views
I have a popup window form that submits data and then upon clicking a link, closes itself and refreshes the parent page. Is there a way to do this after automatically without having to click the link? By that I mean, is there a coldfusion tag that allows for the javascript to run at a certain point in my lines of code (on the cf page my form posts to)?

My close window link code is as follows:

<a href="javascript:;" onclick="opener.location='https://somewebsiteurl.com/#form.somevar#';self.close();">Close Window</a>
    This topic has been closed for replies.

    3 replies

    Inspiring
    August 29, 2008
    Art of Zen wrote:
    > By that I mean, is there a coldfusion tag that allows for the javascript to run at a certain point in my
    > lines of code (on the cf page my form posts to)?

    *AND*

    Art of Zen wrote:
    > That worked! I was worried that the coldfusion code would not run
    > first, but it did.


    I just wanted to bring up the concept here the indicates a fundamental
    and very common beginning misconception.

    The distinction between ColdFusion and JavaScript and how they *do* and
    *do not* relate to each other.

    The former only runs on a server and will never run at the same time as
    the latter which only runs on a client. You can never have ColdFusion
    code and JavaScript code 'interact' with each other in a procedural manner.

    There are very powerful techniques to use ColdFusion to build dynamic
    JavaScript to be sent to and run on the client. There are DHTML|AJAX
    methods to have JavaScript make new requests to a server and have
    ColdFusion generate and then send new content to the client behind the
    scenes. But they do not work 'together', i.e. each one has no clue what
    the other knows or is doing.

    I have repeatedly witnessed the frustration and difficult new web
    programmers have until they grok the deferences between the server code
    and the client code and how the twain will never meet.
    Inspiring
    August 29, 2008
    Ian Skinner wrote:
    > I have repeatedly witnessed the frustration and difficult new web
    > programmers have until they grok the deferences between the server code
    > and the client code and how the twain will never meet.

    Yes, Ian raises a very important point. I was going to post a follow up about this, and was searching for a great link over at houseoffusion.com that outlines the relationships and differences. (I am too lazy to type today). Fortunately, Ian saved me the trouble ;-)

    Inspiring
    August 29, 2008
    Yes, ColdFusion code always executes first. Because CF code runs on the server, whereas javascript runs in the client browser.
    Inspiring
    August 29, 2008
    With a basic window, that is a javascript task. Add some javascript to your submission page and call it on page load. I do not remember the correct syntax offhand, but something like:

    // refresh parent window
    window.opener.location.refresh();
    self.close();
    August 29, 2008
    That worked! I was worried that the coldfusion code would not run first, but it did.

    Thanks!