Tapestry 5 支持 vbscript 吗?

发布于 2024-11-13 23:56:07 字数 1196 浏览 4 评论 0原文

我被要求通过 vbscript 片段“嗅探”用户的 Windows 用户名,但无法在 Tapestry (5.1.0.5) 应用程序中使其正常工作。

Tapestry 似乎试图将 vbscript 解释为 javascript,因此失败了。

vbscript 片段(如下)嵌入到一个组件中,该组件又作为多区域更新的一部分有条件地加载到区域内。

伪 tml:

<page>
    <t:zone>
        <t:if>
            <t:mycomponent>
                <vbscript />

vbscript:

<script type="text/vbscript" language="vbscript">
    Dim shell
    set shell = createobject("wscript.shell")
    set env = shell.environment("process")
    set field = document.getElementById("windowsLoginField")
    if field is nothing then
        alert("no field")
    else
        field.value = env("username")
    end if
</script>

我知道这应该只适用于 IE,但是其他浏览器应该正常失败(不运行脚本)。

当区域在应该呈现 vbscript 的状态下重新加载时,我在 firebug 中收到以下错误:

missing ; before statement
Dim shell 

这是因为脚本正在由 prototypejs 评估:

evalScripts: function() {
    return this.extractScripts().map(function(script) { return eval(script) });
}, 

有谁知道一种方法来避免原型评估此脚本,以便它可以通过并作为vbscript执行吗?

我注意到没有 @IncludeVbScriptLibrary 注释...

谢谢,p。

I've been asked to 'sniff' users' windows username via a vbscript snippet and am having trouble getting this to work in the tapestry (5.1.0.5) application.

It seems tapestry is trying to interpret the vbscript as javascript and therefore failing.

The vbscript snippet (below) is embedded within a component which is in turn loaded conditionally inside a zone as part of a multizoneupdate.

pseudo tml:

<page>
    <t:zone>
        <t:if>
            <t:mycomponent>
                <vbscript />

vbscript:

<script type="text/vbscript" language="vbscript">
    Dim shell
    set shell = createobject("wscript.shell")
    set env = shell.environment("process")
    set field = document.getElementById("windowsLoginField")
    if field is nothing then
        alert("no field")
    else
        field.value = env("username")
    end if
</script>

I am aware that this should only work for IE, however other browsers should fail gracefully (not run the script).

When the zone is re-loaded in a state where the vbscript should be rendered, I get the following error in firebug:

missing ; before statement
Dim shell 

This is because the script is being evaluated by prototypejs:

evalScripts: function() {
    return this.extractScripts().map(function(script) { return eval(script) });
}, 

Does anyone know of a way to avoid prototype evaluating this script so that it can make it through and be executed as vbscript?

I notice there is no @IncludeVbScriptLibrary annotation ...

thanks, p.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时光的容颜 2024-11-20 23:56:07

Tapestry 从原型继承了这个问题。一种解决方案是修补原型 extractScripts 和 evalScripts,以便它们在看到 vbscript 时执行您想要的操作。

这段代码可以工作(在 IE7 和 Chrome 中测试),但它可以变得更灵活(例如,关闭类型而不是语言)

<script type="text/javascript">

String.prototype.extractScripts = function() {
    var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
    var matchOne = new RegExp(Prototype.ScriptFragment, 'im');

    var matchVBScript = new RegExp('<script.*type=(["\'])text\/vbscript\\1');

    return (this.match(matchAll) || []).map(function(scriptTag) {
      return [matchVBScript.match(scriptTag), (scriptTag.match(matchOne) || ['', ''])[1]];
    });
  }

String.prototype.evalScripts = function() {
    return this.extractScripts().map(function(script) { 
      // if it's vbscript and we're in IE then exec it.
      if ( script[0] && Prototype.Browser.IE ) return execScript(script[1], "VBScript");

      // if it's not vbscript then eval it    
      if ( !script[0] ) return eval(script[1]);

    });
}
</script>

Tapestry inherits this problem from prototype. One solution is to patch the prototype extractScripts and evalScripts so that they do what you want when they see vbscript.

This code works (tested in IE7 and Chrome), but it could be made more flexible (keys off of type and not language for instance)

<script type="text/javascript">

String.prototype.extractScripts = function() {
    var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
    var matchOne = new RegExp(Prototype.ScriptFragment, 'im');

    var matchVBScript = new RegExp('<script.*type=(["\'])text\/vbscript\\1');

    return (this.match(matchAll) || []).map(function(scriptTag) {
      return [matchVBScript.match(scriptTag), (scriptTag.match(matchOne) || ['', ''])[1]];
    });
  }

String.prototype.evalScripts = function() {
    return this.extractScripts().map(function(script) { 
      // if it's vbscript and we're in IE then exec it.
      if ( script[0] && Prototype.Browser.IE ) return execScript(script[1], "VBScript");

      // if it's not vbscript then eval it    
      if ( !script[0] ) return eval(script[1]);

    });
}
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文