Tom Muck

Alpha Dog Blues Band
Home page
All articles
All Extensions | Extension News | Extension FAQs | Customer Login
Books authored or co-authored by Tom Muck
Extensions, books, and other products | Customer Login
Your current cart contents
Tom-Muck.com Blog | CMXTraneous Blog | Flash Remoting Blog
About the site

Blog

Tom Muck's Blog: JavaScript and cfhtmlheadTom Muck's Blog

News and Views

JavaScript and cfhtmlhead

Tuesday, February 28, 2006 8:01:13 PM

I don't know why I didn't think of this before, but I found a trick to using <cfhtmlhead> with complex JavaScript. I build a lot of little pods, and frequently need a little JavaScript to go into the document head, but the pod is cfincluded somewhere else. <cfhtmlhead> lets you put content anywhere on the page, and CF will automatically put it in the head for you. This is great, but it breaks color coding in Dreamweaver and other editors and also has problems if you have multiple levels of quotes:

setInterval( "tfm_somefunction('" + className + "'," + red + "," + green + "," + blue + "," + speed + ")", 10 );

Rather than go through the painful process of escaping quotes, use <cfsavecontent>, which places everything into a variable:

<cfsavecontent variable="script">
<script type="text/javascript">
function blah(){
  setInterval( "tfm_somefunction('" + className + "'," + red + "," + green + "," + blue + "," + speed + ")", 10 );
}
</script>
</cfsavecontent>

Then just use the variable in the <cfhtmlhead> tag:

<cfhtmlhead text="#script#">

Color coding now works for the JavaScript in Dreamweaver, and the script is put into the head when the page is passed to the browser.

Category tags: Dreamweaver, ColdFusion

Before posting comments or trackbacks, please read the posting policy.

Full Blog Calendar

Pay me securely with your Visa, MasterCard, Discover, or American Express card through PayPal!
Pay me securely with your Visa, MasterCard, Discover, or American Express card through PayPal!
About | Privacy Policy | Contact | License Agreement | ©2002-2024 Tom Muck | Dreamweaver Extensions