Tip of The Day using CFWindow
Another great tag in ColdFusion 8 AKA Scorpio is the cfwindow tag. This tag create a popup window in the browser without creating a separate browser instance. While I thought this was a great Idea I wasn't quite sure where I would use this. Once I got to thinking I quickly realized that it would be much easier figuring out where I wouldn't use it. This tag is very useful in so many ways and I would like to point out my first idea. This is just a quick example with a little code. If we were going to create an actual tip of the day application we could go much more in depth.
Let us say for example that every time someone visits my blog I want to display a tip of the day to them. Even better you could read in some type of session variable for the users settings or place a cookie on their machine. The session variable would tell us if we should display the tip of the day or not. If so we simply build our new tip of the day window. First off this is another tag that can take attributes as a structure and this seems to be better code to me so I am sticking with it. Here were are just defining the basic properties of our new window. For more information about all of the windows attributes please see the cfml reference.
<cfset win.name = "totd">
<cfset win.title = "Tip Of The Day">
<cfset win.center = true>
<cfset win.closable = true>
<cfset win.draggable = true>
<cfset win.initShow = true>
<cfset win.modal = true>
<cfset win.width = 600>
<cfset win.height = 300>
<cfset win.resizable = true>
<cfif session.showTOTD>
<cfwindow attributeCollection="#win#">
<h4>Did You Know?</h4>
<p>Here are a couple tips when navigating around my website.</p>
<ul>
<li>You can use the search box to the right to search all archived articles</li>
<li>By clicking on a subject under archives by subject you can see a listing of all articles by subject</li>
<li>You can email me using danvega@gmail.com</li>
<li>I use gtalk so you can contact me there as well</li>
<li>Lebron James Is King James to you!</li>
</ul>
</cfwindow>
</cfif>
If you would like to check out the demo I built you can visit the link below. Here is the final code I used.
<html>
<head>
<title>CFWindow / Tip Of The Day</title>
<style>
body,li,p {
font-family:Arial,sans-serif;
font-size:12px;
}
</style>
</head>
<body>
<img src="images/website.jpg">
<!--- show tip of the day --->
<cfset session.showTOTD = true>
<!--- just in case we forgot to set it --->
<cfparam name="session.showTOTD" default="false"/>
<cfset win = structNew()>
<cfset win.name = "totd">
<cfset win.title = "Tip Of The Day">
<cfset win.center = true>
<cfset win.closable = true>
<cfset win.draggable = true>
<cfset win.initShow = true>
<cfset win.modal = true>
<cfset win.width = 600>
<cfset win.height = 300>
<cfset win.resizable = true>
<!--- session variable for tip of the day --->
<cfif session.showTOTD>
<cfwindow attributeCollection="#win#">
<h4>Did You Know?</h4>
<p>Here are a couple tips when navigating around my website.</p>
<ul>
<li>You can use the search box to the right to search all archived articles</li>
<li>By clicking on a subject under archives by subject you can see a listing of all articles by subject</li>
<li>You can email me using danvega@gmail.com</li>
<li>I use gtalk so you can contact me there as well</li>
<li>Lebron James Is King James to you!</li>
</ul>
</cfwindow>
</cfif>
</body>
</html>
http://h127408.cf8beta.com/ajax/tipoftheday.cfm
