tags:

views:

96

answers:

2

We have some ColdFusion apps that use the cfhtmlhead tag to add some scripts and random stylesheet link tags... problem is I can't change the files that do this, and my content has to execute along with the code that has the cfhtmlhead calls. Again, not much I can do to get around this.

The only thing I can think of that almost works is to do a <cfcontent reset="true"> which takes care of everything but the lingering <script>...</script> and <link ... /> tags that were added using <cfhtmlhead />

I just need to know if there is a way to reset or cancel anything that has been added via cfhtmlhead to output some text content that can't have script and link tags or any thing else littering the output.

From what I have tried/found, it doesn't seem possible. Can someone confirm if this is the case? Am I missing some simple or even hackish solution somewhere?

+2  A: 
while (getMetaData(out).getName() is 'coldfusion.runtime.NeoBodyContent')
{
    out = out.getEnclosingWriter();
}
methods = out.getClass().getDeclaredMethod("initHeaderBuffer",arrayNew(1));
methods.setAccessible(true);
methods.invoke(out,arrayNew(1));

http://www.coldfusiondeveloper.nl/post.cfm/clearing-the-cfhtmlhead-buffer-in-railo

Henry
Good find, Henry! :-)
Eric
:) I just asked Google...
Henry
Hmm, I'm getting an error when I try that on my cfml page... Message: Unable to invoke method getDeclaredMethod on object class coldfusion.runtime.NeoBodyContentProbably something with how the server is configured or how the pages are being executed(my file I have access to is one of many in a rather long include chain).Good ideas on the page though, I'll keep looking.
John
maybe "Disable Access To Internal ColdFusion Java Components" is checked? http://help.adobe.com/en_US/ColdFusion/9.0/Admin/WSc3ff6d0ea77859461172e0811cbf3638e6-7ffc.html . If not, contact the blog author.
Henry
Thanks Henry, this doesn't seem to be set on the server though. My code is for a custom tag... maybe that is the reason for the error?
John
Nope, even on a normal cfm page I get this error. I also tried it under a dev install of cf9 where I can check/control things too, the function fails with the same message there too.
John
I might have copy and past the wrong code, have you tried the function at the bottom of the page? There are code needed for CF8/CF9.
Henry
A: 

Thanks to Henry's link and a few other issues I was figuring out at the same time, I got thinking of other ways to hack at it and found this simple solution that works for my original problem as I don't want/need to use content injected via the cfhtmlhead call at all:

<!--- output that doesn't work with the headerText being added to it --->
<cfsavecontent variable="dontLitter">
...
</cfsavecontent>

<cfcontent type="text/html" variable="#toBinary(toBase64(dontLitter))#" />

This works because when using the <cfcontent> tag with the variable attribute all previous output is discarded, including anything set with the <cfhtmlhead> - which is what was needed.

John