【问题标题】:html code that executes wsh code through javascript通过javascript执行wsh代码的html代码
【发布时间】:2014-11-14 01:42:06
【问题描述】:

我卡在这段代码上...我正在尝试获取 html 页面,当您单击链接时,调用 bms 函数,该函数应该打开 Internet Explorer,转到 google,然后填写搜索文本框用“测试”这个词。这不完全是我想要使用的网站或字词,但我需要更改它,因为实际的网站/字词是敏感信息。我想通过 IE 使用它,因为我们的进程通过这个浏览器,特别是还使用 -nomerge 函数。我的代码如下。感谢您的帮助!

<html>
<head>    
<script>
var WshShell = new ActiveXObject("WScript.Shell");
function BMS()
{
WshShell.Run("iexplore.exe -nomerge http://google.com");
WScript.Sleep (5000);
WshShell.SendKeys ("test");
WScript.Quit();
}
</script>
</head>
<a href="#" onclick="javascript:BMS();">BMS</a>
<br /><br />
<a href="#" onclick="javascript:DAY();">DAY</a>
</html>​

【问题讨论】:

  • 您不需要在 onclick 值前面加上 javascript,但我不确定它是否会伤害任何东西……尽管您似乎错过了 body 标记。所以,我会做的就像我的答案一样......传入
  • 文本输入是真正的要求吗?为什么不向 URL 添加一个查询字符串以匹配 Google 的表单将提交的内容?
  • 我实际上不需要对搜索引擎进行查询,我只是这样做是因为我无法输入敏感信息,所以我稍微更改了脚本。我正在寻找一种我可以编辑/使用的方法,而不是实际去谷歌输入“test”

标签: javascript html wsh


【解决方案1】:

不要被玉甩掉;它只是更快。请注意,我将脚本放在结束正文标记之前。

html
  head
    title foo
  body // body tag added
    p notice that i've not declared script yet. Preference/good practice.
    a#bsdTrigger(href='#') foo    
    a#ssddTrigger(href='#') bar
    //- scripte here

重要部分:here's a pen

 (function() {
    // now the variable will not pollute your global ns
    var WshShell = {}; //ignore the OR only because there is no Active thing

    WshShell.log = function() { // fake behavior for testing
        console.log(arguments);
    } 

    var bsd = function BSD() {
        WshShell.log("foo");
        window.alert('foo!');
        return false;
    }

    document.getElementById("bsdTrigger").addEventListener('click', bsd);
})();

我希望这会有所帮助...它非常通用且做作,但您会使用完全相同的方法来做您想做的事情。

【讨论】:

  • 我不知道“这里有一支笔”链接发生了什么,但它不再工作,我无法查看任何内容,也无法让此代码工作。你怎么又弄到了?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-23
  • 1970-01-01
  • 2014-12-05
  • 2019-03-30
  • 1970-01-01
  • 2022-11-18
  • 2012-12-09
相关资源
最近更新 更多