The Thinking Lemur

26 Sep, 2007

Refreshing a CFWindow

Posted by: Donnie Bachan In: ColdFusion| Javascript

Recently I came across the situation where I wanted to refresh a cfwindow with a source tag that was bound to a hidden form field. When the value of the form field changed I wanted the window information to be reloaded, however since the value was being changed via javascript the onChange event was not being fired on the hidden field and so the cfwindow was not refreshing. I then decided to take another approach. I would use the ColdFusion.Window.create function and create a new window each time it is needed. In order to not have multiple instances of the window I would destroy the old window before creating the new one.

<code>
function getPageId()
{
return pageid;
}

function createWindow(name)
{

try
{
twin = ColdFusion.Window.getWindowObject(name);
twin.destroy(true);
}
catch (e)
{
// do nothing because the window does not exist
}
ColdFusion.Window.create(win, ‘Edit Page Properties’,
‘test.cfm?id=’+getPageId(),
{height:750,width:960,modal:true,closable:false,
draggable:false,resizable:true,center:true,initshow:true})

}
</code>

If I pass the same window name each time the window never refreshes! Even though pageid is changing. This seems to be because the window object is cached somehow. When I set the destroy(true) parameter another error comes up since the element is removed completely from the DOM. To work around this, each window created MUST have a unique name. If the name is not unique errors will occur since it seems that CF caches the name used for a window. I am not sure where and am in no mood to look for it at this point. Here is the code that works.

<code>
var winname = ”;

function getPageId()
{
return pageid;
}

function createWindow(name)
{
win = name + “_os_” + Math.round(Math.random() * 10000000000);
try
{
twin = ColdFusion.Window.getWindowObject(winname);
twin.destroy(true);
}
catch (e)
{
// do nothing because the window does not exist
}
ColdFusion.Window.create(win, ‘Edit Page Properties’,
‘test.cfm?pageid=’+getPageId(),
{height:750,width:960,modal:true,closable:false,
draggable:false,resizable:true,center:true,initshow:true})
winname = win;
}
</code>

No Responses to "Refreshing a CFWindow"

Comment Form

You must be logged in to post a comment.