Tuesday, October 15, 2013

OpenBD, CFAjaxProxy, and HTML 4 Strict

I've been working on a site using the HTML 4 Strict doctype, and it's all good except for one issue.

I'm also using CFAjaxProxy, which inserts a dynamic JS link in the header, the problem is that in OpenBD 2.0.2 the code looks like this:

<script src="load.cfres?js=cfajaxproxy01.js"></script><script src="load.cfres?js=cfc48774055.js"></script>

In HTML 4 Strict, the script tag should have the type also set, which causes the validation to fail. Granted, this is not a big issue in any way, it just nagged me so I decided to solve it.

The solution is very simple, we'll use a combination of render() and replace() to generate the dynamic tag, and append the type.
Here's the line:
#Replace(Render('<cfajaxproxy cfc="test" jsclassname="jscfc">'), '">','" type="text/javascript">','ALL')#

Breaking it down, the first thing to run is the Render() code, which runs the tag and returns the output, creating our dynamic output, from that we get the above <script> block.
Then Replace() runs, where we look for "> and replace it with " type="text/javascript">

And finally, because we're doing doing this in CFML, it's all done on the server, before the page is rendered, so the client browser just receives a fully working, properly formatted script tag.

I haven't tried this with other things, but using render and replace we should be able to adjust just about any tag we need.

No comments:

Post a Comment