开发者

How do I put Javascript in the <head> element of a Coldfusion Model Glue page?

开发者 https://www.devze.com 2023-03-31 00:52 出处:网络
I have a Model Glue CFM page index.cfm with some JS code that I\'d like to execute: <script type=\"text/javascript\">

I have a Model Glue CFM page index.cfm with some JS code that I'd like to execute:

<script type="text/javascript">
    $(function() {
        $('#text').height(300);
    });
</script>

<p id="text">This is some text</p>

This is being inserted into a CFM template that looks like this:

<html>
    <head>
        <script type="text/javascript" src="js/jquery.js"></script>
    </head>

    <body>
        <cfoutput>#viewCollection.getView("body")#</cfoutput>
    </body>
</html>

And the relevant part in ModelGlue.xml:

<event-handler name="page.index">
    <views>
        <include name="body" template="pages/index.cfm"/>
        <include name="main" template="templates/main.cfm"/>
    </views>
</event-handler>

Unfortunately, this will stick the Javascript portion directly into the body. Is there a way to put it in the <head> tag without 开发者_运维问答having to create a separate CFM file, similar to how the ASP.NET MVC 3 Razor @section tag works?


You can use <cfhtmlhead>

For more details, see the docs here.


You can put JavaScript code in head section of Master.Layout.cfm. you can also put on body section in page from where you are calling JavaScript function.

0

精彩评论

暂无评论...
验证码 换一张
取 消