开发者

does tapestry 5 support vbscript?

I've been asked to 'sniff' users' windows username via a vbscript snip开发者_C百科pet 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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜