Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Running Javascript Code to Close Window at end of page

Guest
Aug 28, 2008 Aug 28, 2008
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>
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 28, 2008 Aug 28, 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();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 29, 2008 Aug 29, 2008
That worked! I was worried that the coldfusion code would not run first, but it did.

Thanks!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 29, 2008 Aug 29, 2008
Yes, ColdFusion code always executes first. Because CF code runs on the server, whereas javascript runs in the client browser.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 29, 2008 Aug 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 29, 2008 Aug 29, 2008
LATEST
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 ;-)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources