How to fix CFWINDOW so the contents of the window layer are not visible on page load

Right, well I've been having lots of fun playing with the new super-duper CFWINDOW tag in CF8. What this lovely tag does is it allows you to quickly create impressive lookng web 2.0 style windows. The coolest feature of the tag is the ability to set a window as 'modal'. This makes the window one of those where the background of the page is greyed out with only the window being usable.. Very neat for login panel's etc. I'm making extensive use of this technology on the big project I'm currently working on.

Anyway, I became aware of an annoying problem today where the actual contents of the CFWINDOW was appearing at the top of the page while it was loading. Once loading was complete the content would dissapear as the Ajax goodness kicked in to hide it.. Well obviously on a production site this is simply not workable - we can't have our vistors seeing ugly text at the top of the design only to watch it vanish when the page is fully rendered.

Well anyway after an inspired moment about 10 minutes ago I realised that the key was to make sure the generated <div>'s tags that CFWINDOW creates to hold the window contents are set to render off screen. The fix is the incredibly complex piece of CSS ( :) ) that you need to add to your stylesheet:

.yuiextdlg {
    position:absolute;
    left:-200px;
}

You may need to play with the left offset if your CFWINDOW dimensions are quite wide.

This works a treat and ensures that all your CFWINDOW pages are loaded properly.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Curt Gratz's Gravatar James,

Thanks for posting this. It was driving me crazy on one site I developed.
This post was a huge help.

Curt
# Posted By Curt Gratz | 4/30/08 9:41 PM
James Allen's Gravatar Hey there Curt,

No problem at all! It did my head in for hours before I solved it. I went searching and couldn't find any solutions, just a few reports of the issue.

Glad this has helped you out, though I wonder if it was fixed in CF8 update 1. That's not something I tested.
# Posted By James Allen | 5/1/08 1:23 PM
WeBoat's Gravatar Fantastic help. Sometimes the simple things. I've just started using CFWINDOW and was about to shelve it when I saw your post for this issue/bug
# Posted By WeBoat | 5/25/08 10:27 PM
James Allen's Gravatar Excellent! Glad I was able to help. I was like you and was about to dump CFWINDOW until I found a solution.

There are some cool Ajax functions in CF8.. If you haven't checked it out already - CFAJAXPROXY is another essential - really great.
# Posted By James Allen | 5/26/08 1:48 PM
Uday's Gravatar superb,Amazing, outstanding support. Thanks Thanks Thanks
# Posted By Uday | 8/20/08 7:34 AM
kotesh's Gravatar Hi James,
Thanks a lot for your posting. keep rocking.
# Posted By kotesh | 9/3/08 6:44 PM
Jokey's Gravatar Thanks for this. Was driving me nuts
# Posted By Jokey | 12/24/08 6:35 PM
Ian's Gravatar I don't know what the heck your CSS magic means, but its sweet.
# Posted By Ian | 3/11/09 5:03 PM
James Allen's Gravatar LMAO.. Thanks Ian.
# Posted By James Allen | 3/11/09 5:07 PM
Garry's Gravatar Hi James,

Is it possible for a cfwindow window to load the contents of the cfwindow AFTER the a button to view the cfwindow is clicked? The problem with my page is that it loads the page really slow since I have about six cfwindows with flash forms loading. Thanks!
# Posted By Garry | 4/22/09 8:53 PM
James Allen's Gravatar Hi Garry,

I've just checked this out and the way to do this is to use the 'source' attribute. This takes a template as a parameter and will only load it when the user clicks the trigger button / link.

So in your case, just create separate .cfm files for each window or have a single window.cfm handler which you pass params into, to tell it what to render.

E.G window.cfm?mode=userpanel

That should do the trick nicely..
# Posted By James Allen | 4/22/09 9:50 PM
Garry's Gravatar Thanks for the response James. I've been a bit preoccupied so I haven't had the time to test this out. Finally got to it this morning, however, there seems to be a problem when the source file is a flash form... it loads the page but it opens it in the entire window, and the form is unable to be used.

Again, thanks for helping!
# Posted By Garry | 5/5/09 5:36 PM
James Allen's Gravatar Damn, sorry about that Garry. I've never used flash forms so I'm not quite sure how they work or why they would throw things out like that.

Hopefully there is a work-around. If you do find one let me know what it is.
# Posted By James Allen | 5/5/09 5:47 PM
Tristan's Gravatar Wow thanks. I have read on other sites about this little glitch and it has been very annoying. I had to set my offset to -2000px due to the width of my screen, but otherwise it works perfectly. Thanks!
# Posted By Tristan | 7/24/09 9:33 PM
James Allen's Gravatar Hey there Tristan. No problem at all. I really don't understand why Adobe didn't fix that problem in 8.0.1. Be interesting to see if it's been sorted in CF9 thinking about it.
Simple fix but a very annoying problem to solve.
Glad I could help.
# Posted By James Allen | 7/25/09 12:51 PM
Jacintha's Gravatar hi James,

I'm redirected to a new page when I click a button in cfwindow and the cfwindow gets closed automatically.Is it possible for the cfwindow to remain open until the user closes it.
# Posted By Jacintha | 6/24/10 2:05 PM
James Allen's Gravatar Hey there Jacintha,

I haven't worked with CFWindow for a long time but to do what your looking for you need to use Ajax.

I'd use something like JQuery to use an Ajax load for each link or I think there is a Coldfusion Ajax function to load another page into a div.

In Jquery you'd do something like this:

<javascript src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/...; type="text/javascript"></script>

<javascript language="javascript">
   function loadPage(page) {
      $("#loader").load(page);
   }
</script>

<a href="javascript:loadPage('firstpage.cfm');">First Page</a>

<div id="loader"></div>

In the above, when the user clicks the 'First Page' link, JQuery will be used to load up the firstpage.cfm into the div with id="loader".

I'm sure there is a way to do this in a Coldfusion Ajax way as well.
# Posted By James Allen | 6/24/10 3:49 PM
May May's Gravatar what a quick fix!!! wonderful!!!
# Posted By May May | 8/6/10 7:00 AM
© 2010 James Allen | Contact Me
This blog runs on the awesome power of BlogCFC - created by Raymond Camden. This blog is running version 5.9.