I have a ColdFusion page that on it, has several cfinclude template calls which include separate files into the page. I would like to update a javascript variable before each cfinclude template call. I've tried using:

我有一个ColdFusion页面,上面有几个cfinclude模板调用,其中包含单独的文件到页面中。我想在每个cfinclude模板调用之前更新一个javascript变量。我尝试过使用:

<script type="text/javascript">
myvariable = 'new status';
</script>

However, the javascript doesn't get executed until every single template included on the page finishes processing, instead of before each one executes.

但是,直到页面上包含的每个模板完成处理,而不是在每个模板执行之前,javascript才会执行。

Is there some way I can actually execute javascript code AS the page loads?

有没有办法在页面加载时实际执行javascript代码?

1 个解决方案

#1


4

You can accomplish this with <cfflush>.

您可以使用 完成此操作。

CFFlush will send the current HTML/javascript output to the browser as it continues to process. It would look something like this:

CFFlush会在继续处理时将当前的HTML / javascript输出发送到浏览器。它看起来像这样:

<CFInclude template="process1.cfm">
<CFoutput>
    <script type="text/javascript">
    myvariable = 'new status';
    </script>
</CFoutput>
<cfflush>
<CFInclude template="process2.cfm">

... and repeat.

......并重复一遍。

The javascript will be interpreted by the browser as soon as it is loaded. This sometimes causes unpredictable behavior since the DOM is not complete and in a ready state, but for simple operations it works.

浏览器加载后将立即解释javascript。这有时会导致不可预测的行为,因为DOM不完整且处于就绪状态,但对于简单的操作,它可以工作。

Edit: note that you often have to pad your output with something like <cfoutput>#repeatString(" ", 250)#</cfoutput> before the browser will process it. See http://www.raymondcamden.com/index.cfm/2006/11/29/A-Loading-page-with-CFFLUSH-and-JavaScript

编辑:请注意,在浏览器处理输出之前,您经常需要使用 #repeatString(“”,250)# 之类的输出填充输出。请参阅http://www.raymondcamden.com/index.cfm/2006/11/29/A-Loading-page-with-CFFLUSH-and-JavaScript

更多相关文章

  1. 如何在页面上获得带有javascript的特定单词的链接
  2. 我可以在JavaScript中从不同的页面传递参数吗?
  3. Ajax的实用技术——用户的注意力从页面的其他区域到转移选择的图
  4. 不断更改页面(例如cookie点击器中的cps)
  5. 切换页面时出现白屏闪烁
  6. 使用CSS,HTML和Javascript在随机图像的页面上进行图像大小调整
  7. 如何在涉及css缩放时获取页面上的点击位置
  8. 如何修复一个页面网站的容器/正文宽度(html,css和js)
  9. swiper 定位到指定页面或位置

随机推荐

  1. Android 从零开始打造异步处理框架
  2. LinearLayout中实现水平方向上的两个text
  3. 最全的PHP开发Android应用程序
  4. 用Gradle 构建android程序
  5. 第四周Android实习笔记
  6. 裁判文书android app逆向
  7. Mono for Android V1.0 正式发布啦!
  8. 从linux看Android之一--init进程
  9. Android Scripting Environment -ASE
  10. Android(安卓)make 中变量记录