Changing the text of a CFWINDOW

A quick tip - how do you change the text of a window created by CFWINDOW? All you need to do is grab the underlying window object:

var win = ColdFusion.Window.getWindowObject("mywin");

In this object there is a body property which is a complex structure pointing to the body of the window. I thought perhaps the body was a simple string. I did:

win.body = 'Chicago better not be too cold';

Which didn’t work (nor did it throw an error). Then I used ColdFusion’s Ajax debugger:

ColdFusion.Log.dump(win.body);

This revealed the entire body element and I saw that there was a dom key which pointed to the DOM object. So all together now - the code is:

var win = ColdFusion.Window.getWindowObject("mywin"); win.body.dom.innerHTML = "Hi Ray, how are you?";

And there is a complete template for you to try:

<script> function test() { var win = ColdFusion.Window.getWindowObject("mywin"); win.body.dom.innerHTML = "Hi Ray, how are you?"; } </script>

<cfwindow name=”mywin” width=”400” height=”400” closable=”true” initShow=”true” title=”Test”> Initial Content </cfwindow>

<form> <input type=”button” onClick=”test()” value=”test”> </form> </code>

Edit: Please be sure to read Todd’s comment below. There is a simpler way to do what I did above. I’d nuke my own entry - but I figure the alternative I used would still be of interest to folks.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments