简体   繁体   中英

HTA: Javascript functions inside of VBScript string causes error in HTA?

I'm using both javascript/vbscript in my HTA and am building the table for my HTA interface inside of a VBS loop. When I simply run:

strHTML = strHTML & "<tr>" &_ 
        "<td><a id=""" & aName & """ href=""javascript:toggleRow('" & rowName & "','" & arrTemp(1) & "','" & aName & "')"">+ </a>" & arrTemp(1) & "</td>" & _
        "<td>" & arrTemp(2) & "</td><td class='status'>" & _
        "<img onclick=""displayRow()"" src='" & strStatus & "' border='0'></td></tr>" & _
        "<tr id='" & rowName & "' style=""display:none;""><td id='" & arrTemp(1) & "' colspan=""3"">test</td></tr>"

...my HTA displays fine. But when I try to add Javascript functions to my TR tag, I get all sorts of VBS errors:

strHTML = strHTML & "<tr onmouseover=""ChangeColor(this, true);"" onmouseout=""ChangeColor(this, false);"" onclick=""DoNav();"">" &_ 
        "<td><a id=""" & aName & """ href=""javascript:toggleRow('" & rowName & "','" & arrTemp(1) & "','" & aName & "')"">+ </a>" & arrTemp(1) & "</td>" & _
        "<td>" & arrTemp(2) & "</td><td class='status'>" & _
        "<img onclick=""displayRow()"" src='" & strStatus & "' border='0'></td></tr>" & _
        "<tr id='" & rowName & "' style=""display:none;""><td id='" & arrTemp(1) & "' colspan=""3"">test</td></tr>"

I'm pretty sure I've commented out the extra quotations correctly but I can't get it to work. Can anyone see what I'm doing wrong just on the first line?

Edit: Additionally, if i leave all of the on* events with their associated 4 quotes but remove all of the internal javascript functions, the page loads fine if that helps at all

Ah... found the answer. the HTA was interpreting the functions as VBS functions. An explicit declaration to javascript is what did the trick:

strHTML = strHTML & "<tr onmouseover=""javascript:ChangeColor(this, true);"" onmouseout=""javascript:ChangeColor(this, false);"" onclick=""javascript:DoNav();"">" &_ 
                          "<td><a id=""" & aName & """ href=""javascript:toggleRow('" & rowName & "','" & arrTemp(1) & "','" & aName & "')"">+ </a>" & arrTemp(1) & "</td>" & _
                          "<td>" & arrTemp(2) & "</td><td class='status'>" & _
                          "<img src='" & strStatus & "' border='0'></td></tr>" & _
                          "<tr id='" & rowName & "' style=""display:none;""><td id='" & arrTemp(1) & "' colspan=""3"">test</td></tr>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM