Javascript 从 VBS 调用的代码在运行时抛出未指定的错误

Javascript code called from VBS throwing unspecified error at runtime

我有一个网页,我想在其中添加 jQuery 库,这是代码:

var script = document.createElement('script');
script.src ="https://code.jquery.com/jquery-1.11.3.min.js";
document.body.appendChild(script);

此代码是使用 VBS 代码从 UFT 调用的:

script= "var script = document.createElement('script');" &_
        "script.src =" & chr(34) & "https://code.jquery.com/jquery-1.11.3.min.js" & chr(34) & ";" &_
        "document.body.appendChild(script);"
Browser("myBrowser").Page("myPage").RunScript(script)

当我 运行 我的 VBS 代码时,抛出一个错误

"Erreur non spécifiée" | in English "unspecified error"

但我无法弄清楚为什么会抛出此错误,因为 VBS 和我的 js 代码似乎都正常...我正在使用 IE 8 企业模式并且在安全选项中启用了脚本。 我对如何解决这个问题没有更多想法...

谢谢,

UFT's online documentation:

When running this method, you should use an eval() function or anonymous function to run the script entered for this method. For example, you can use functions like these:

"eval(var remove = document.getElementsByTagName('a')[0]; var per = remove.parentNode; per.removeChild(remove););"

OR "(function(){var remove = document.getElementsByTagName('a')[0]; var per = remove.parentNode; per.removeChild(remove);})();"*

请查看修改后的代码,该代码进行了一些更改

  1. 代码放在anonymous function and immediately executed (IIFE)
  2. 我使用单引号而不是 chr(34)(这没有什么区别,只是更具可读性)。

    script = "(function(){" &_ 
      "var script=document.createElement('script');" &_  
      "script.src='https://code.jquery.com/jquery-1.11.3.min.js';" &_  
      "document.body.appendChild(script);" &_   
    "})();"