Tom Muck's Blog
News and Views
1 post
on 02/28/2006
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
Posted by Tom Muck
Add comment |
View comments (1) |
Permalink
|
Trackbacks (0)
|
Digg This
1 post
on 02/28/2006
Before posting comments or trackbacks, please read the posting policy.