javascript - 给 HTML 时间来呈现其文本

标签 javascript html internet-explorer vbscript hta

我有一个非常长的 VBScript 代码,它在 HTA 中运行。该脚本包括 DOM 操作、DLL 调用和其他脚本。现在我遇到了一个问题,因为有很多脚本会暂停 HTML 解析,因此需要花费大量时间在屏幕上呈现文本。

现在我计划创建一个简单的延迟,它会阻止代码执行,但不会阻止 HTML 解析。但我不知道该怎么做。

更新

这是我想要的示例代码(抱歉,请不要介意我对 HTA vbs 不熟悉的语法)

Sub Window_Onload()
    Call Main()
End Sub

Sub Main()
    Dim delay
    el.innerHtml = "Please"
    el2.innerHtml = "Help"
    el3.innerHtml = "me"

    'more scripts here
    'more scripts here
    'more scripts here
    'more scripts here

    el4.innerHtml = "this element is dependent to other scripts"
    el5.innerHtml = "this element is dependent to other scripts"
    el6.innerHtml = "this element is dependent to other scripts"

    delay = 2
    Call PauseAndRenderHtml(delay) 'this function will block the code execution
                                   'but not the html parsing

   'more scripts here

    Do While True
       'very long scripts that loops and pause, loops and pause........
    Loop
End Sub

Sub PauseAndRenderHtml(timeToBreath)
   'Take a breath :)
   'breath/pause for timeToBreath seconds
End Sub

我需要函数PauseAndRenderHtml()

最佳答案

也许是一个计时器,如描述的 here可能有帮助:

<head>
<title>Sample</title>
<HTA:APPLICATION ID="oHTA"
     APPLICATIONNAME="Sample"
>
</head>

<script language="VBScript">
  idTimer = window.setTimeout(GetRef("PausedSection"), 10000, "VBScript")

  Sub PausedSection
    ContinueWork
    window.clearTimeout(idTimer)
  End Sub

  Sub ContinueWork
    'other code here
  End Sub
</script>

<body>
...
</body>

关于javascript - 给 HTML 时间来呈现其文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30435550/

相关文章:

javascript - 使用 Mocha 和 Superagent 在裸 Node.js 应用程序中测试帖子

javascript - 使用 jquery 基于 ajax 的轮询中的 setTimeout 问题

html - landingspage 的 CSS 不断被覆盖?

javascript - IE 不显示在 Javascript 中完成的更新的 IMG SRC 更改

internet-explorer - 在 Internet Explorer 中工作但在 Firefox 中不起作用

html - CSS 垂直对齐 anchor 在 li 内 - IE8/IE9 问题

javascript - Edge 的composedPath 的替代方案

javascript - Angular 依赖未加载

javascript - 在脚本中设置 src 时未加载视频

javascript - 选择和广播 - JavaScript