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>
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.
Archived Comments
I do not fault you for missing this in the docs, but there is a much easier way (pg 622 of dev guide):
"You can use the special controlName_body variable to access and change the body contents for cfpod and
cfwindow controls. For example, you can use the controlName_body.innerHTML property to set the body HTML.
For cfpod and cfwindow tags, you can also use the controlName_title to get or set the control’s title bar contents."
This is really buried in the docs - it should be easier to find.
Nice demo.
Are you aware of any scripts that will automatically remember the windowing positions? This would be perfect for OPML (lists + windows).
Todd - doh - I remember that now. Still though - was kind of interesting to dig into the object a bit.
Scott - that would be kind of simple. As you know, you can easily specify the X,Y for the window when it is started. So all you need to do is remember the window's position. You can use JS to set cookies. So you can either try to capture the window movement, or just poll every second and store. It would be 'cleaner' to note the movement and use an event.
Forgive the huge code post here in the comments, but I don't hvae much time to post a blog entry about this.
Here's how you could capture the x/y for use on other pages:
<cfparam name="cookie.x" default="100" />
<cfparam name="cookie.y" default="100" />
<html>
<head>
<script>
moveListener = function(){
var w = ColdFusion.Window.getWindowObject('win2');
w.on('move', setCoords, w);
}
setCoords = function(ob,x,y){
var today = new Date();
var expire = new Date();
var days = 1;
expire.setTime(today.getTime() + 3600000*24*days);
document.cookie = 'x'+ "=" + x + ";expires="+expire.toGMTString();
document.cookie = 'y'+ "=" + y + ";expires="+expire.toGMTString();
}
</script>
</head>
<body onload="javascript:moveListener();">
<cfwindow name="win2" title="window 2" initShow="false" center="false" x="#cookie.x#" y="#cookie.y#">window two</cfwindow>
<a href="javascript:ColdFusion.Windo...('win2')">Show Win</a><br />
<a href="win1.cfm">Go to page 1</a>
</body>
</html>
PS - I caught the 7 day forecast for Chicago yesterday...it didn't look pretty.
Todd ... sweet demo!
I think I'll want to submit the x/y coordinates to the server over AJAX which would dynamically regenerate an OPML file. I've forgotten the exact spec but OPML has properties for x,y (&z). The cookie would then identify which OPML.