用于从剪贴板中的表自动填充活动浏览器窗口中的字段的脚本

时间:2013-11-29 06:31:24

标签: javascript jquery html vb.net outlook

基本上我想编写一个脚本来粘贴从outlook中复制的表中的特定单元格到活动Web表单中的相应字段。

Web表单URL将根据其唯一引用号更改,CommentID与以下示例中的986734一样:https://xxx.xxx.com.au/trisprod/comment_line/cmnt_action.cfm?CommentID=986734&Refresh=TRUE

当表格粘贴到记事本中时,它会被行和标签分开:

编辑:我刚刚意识到我无法发布没有10个代表的图片,因此从outlook中复制并粘贴

First name      Test
Last name       Test
Phone number    8888 8888
Email address   xxx@xxx.com.au

Response required   Yes
Route/line          180
From location       CBD
To location         XXX
Travel date         20/11/2013
Travel time         10:38 am
Comments    something something somethingsomething something somethingsomething something somethingsomething something somethingsomething something something

因此总共会有11个字段:First name, Last name, Phone number, Email address, Response required(yes/no,true/false), Route/line, From location, To location, Travel Date, Travel timeComments

如果缺少其中一个输入,脚本就会移动到下一个字段。

在firefox中使用Inspect Element (Q)函数后,以下捕获显示前几个字段:![Heading Capture] [2]

![HTML?页面![] [3]] [3]

无论使用哪种浏览器,无论是firefox还是IE,脚本都必须工作。

因此基本上将表格复制到剪贴板,然后点击Web表单使其成为活动窗口,然后运行脚本将剪贴板数据粘贴到正确的字段中,理想情况下由热触发键。

我是一个完整的Noob,很乐意研究,但甚至不确定开始学习什么语言或搜索什么术语 - 似乎我只是绕圈子走了。任何有关开始学习的语言或任何可能有用的教程方向的帮助都将非常感激。如果不相关,请提前致谢并对标签表示抱歉。

编辑,我刚刚意识到我无法在没有10个代表的情况下发布图片,因此请在firefox中从Inspect Element (Q)函数进行复制和粘贴:

<form name="frmCmnt_actions2" method="post" target="_top" action="cmnt_action_update.cfm?Step=0&amp;Refresh=TRUE">
    <input name="CommentID" value="986734" type="hidden">
    <input name="SubmitOption" value="FWD" type="Hidden">
    <h3>Enter New Comment &nbsp;&nbsp; #986734</h3>
    <table border="0" cellpadding="2" cellspacing="1" width="100%">
        <tbody>
            <tr>
                <td class="TableHead"> <strong>Description:</strong><font color="#ff0000" size="-2">*</font> <br>
                    <font size="1">(max 4000 chars)</font> </td>
                <td class="smTable" colspan="2">
                    <textarea onfocus="this.rows=25" onblur="checkSize(this,4000);this.rows=8" name="Description" rows="8" cols="72" wrap="soft"></textarea>
                </td>
                <input name="DialogResponses" type="hidden">
            </tr>
            <tr>
                <td class="TableHead"><strong>Comment Type:</strong><font color="#ff0000" size="-2">*</font></td>
            </tr>
            <tr>
                <td class="tablehead">
                    <input name="RDDay" value="29" type="hidden">
                    <input name="RDMth" value="11" type="hidden">
                    <input name="RDYr" value="2013" type="hidden">
                    <strong>Reported:</strong> </td>
                <td colspan="2" class="smTable"><strong>29/11/2013</strong></td>
            </tr>
            <tr>
                <td class="TableHead"><strong>Incident Date:</strong><font color="#ff0000" size="-2">*</font></td>
                <td colspan="2" class="smTable">
                    <input name="IncidentDay" id="IncidentDay" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,1,31,'Incident Day',true);" type="Text">
                    <input name="IncidentMth" id="IncidentMth" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,1,12,'Incident Month',true);" type="Text">
                    <input name="IncidentYr" id="IncidentYr" required size="4" maxlength="4" value="" onblur="checkIntegerWithinRange(this,2000,2099,'Incident Year',true);" type="Text">
                    <input name="IncidentDate" type="Hidden">
                    &nbsp;&nbsp;&nbsp;
                    <input class="Button" value="Today" onclick="setIncidentDateToToday();" type="Button">
                </td>
            </tr>
            <tr>
                <td class="TableHead"><strong>Incident Time:</strong></td>
                <td colspan="2" class="smTable">
                    <input name="IncidentHr" id="IncidentHr" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,0,23,'Incident Hour',true);" type="Text">
                    <input name="IncidentMin" id="IncidentMin" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,0,59,'Incident Minute',true);" type="Text">
                    24 Hr</td>
                <input name="IncidentTime" type="Hidden">
            </tr>
            <tr>
                <td class="TableHead"><strong>Incident Location:</strong></td>
                <td colspan="2">
                    <input name="IncidentLocation" id="IncidentLocation" required size="30" maxlength="100" value="" type="Text">
                </td>
            </tr>
            <tr>
                <td class="TableHead"><strong>Service Destination:</strong></td>
                <td colspan="2">
                    <input name="ServiceDestination" id="ServiceDestination" required size="30" maxlength="100" value="" type="Text">
                </td>
            </tr>
            <tr>
                <td class="TableHead"><strong>Service Departure Time:</strong></td>
                <td colspan="2" class="smTable">
                    <input name="ServiceDepartureHr" id="ServiceDepartureHr" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,0,23,'Service Departure Hour',true);" type="Text">
                    <input name="ServiceDepartureMin" id="ServiceDepartureMin" required size="2" maxlength="2" value="" onblur="checkIntegerWithinRange(this,0,59,'Service Departure Minute',true);" type="Text">
                    24 Hr</td>
                <input name="ServiceDepartureTime" type="Hidden">
            </tr>
            <tr>
                <td class="TableHead" width="20%"><strong>Service Direction:</strong><font color="#ff0000" size="-2">*</font></td>
                <td class="smTable" colspan="2">
                    <table border="0" cellpadding="0" cellspacing="0">
                        <tbody>
                            <tr>
                                <td>
                                    <input name="ServiceDirection" value="T" type="radio">
                                    Inbound&nbsp;&nbsp;</td>
                                <td>
                                    <input name="ServiceDirection" value="F" type="radio">
                                    Outbound&nbsp;&nbsp;</td>
                                <td>
                                    <input name="ServiceDirection" value="R" type="radio">
                                    Regional&nbsp;&nbsp;</td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
    </td>
    </tr>
    <tr>
    <td class="TableHead">&nbsp;</td>
    <td class="smTable" colspan="2">
    <table border="0" cellpadding="0" cellspacing="0">
    <tbody>
        <tr id="extra1_bus_busno" style="">
            <td class="smTable"><strong>Bus Number:</strong></td>
            <td class="smTable">
                <input name="BusNumber" id="BusNumber" size="10" maxlength="200" value="" type="text">
            </td>
        </tr>
        <tr id="extra1_bus_routecode" style="">
            <td class="smTable"><strong>Route:</strong></td>
            <td class="smTable">
                <input name="RouteName" id="RouteCode" size="10" value="" type="text">
                <input class="Button" value="Find" onclick="FindRoute();" type="Button">
            </td>
        </tr>
        </option>
            <option value="1182">1 </option>
            <option value="1025">2 </option>
            <option value="1026">3 </option>
            <option value="1045">4 </option>
            <option value="1047">5 </option>
            <option value="1048">6 </option>
            <option value="1049">7 </option>
        </select>
    </td>
    </tr>
    </tr>
    <tr>
        <td class="TableHead"><strong>Respondent:</strong> <font color="#ff0000" size="-2">*</font></td>
        <td colspan="2" class="smTable">
            <textarea name="RespondentName" id="RespondentName" rows="2" cols="60" wrap="soft" readonly onfocus="setRespondents();"></textarea>
            <br>
            <input checked="" name="ckEmail" type="Checkbox">
            &nbsp;Send an E-mail to the respondent
            <input name="radEmailOpt" checked="" type="Radio">
            Automatic
            <input name="radEmailOpt" onclick="CheckNavforEmail()" type="Radio">
            Pop-up (for attachments)
            <input value="" name="RespondentEmail" type="Hidden">
            <input name="blnEmail" value="Y" type="Hidden">
        </td>
    </tr>
    </td>
    </tr>
    <tr>
        <td colspan="3">
            <hr>
        </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>First Name:</strong> <font color="#ff0000" size="-2">*</font></td>
        <td class="smTable">
            <input name="CustName" size="25" maxlength="100" value="" type="Text">
        </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Surname:</strong> <font color="#ff0000" size="-2">*</font></td>
        <td class="smTable">
            <input name="CustSurname" size="25" maxlength="100" value="" type="Text">
        </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Title:</strong></td>
        <td class="smTable">
            <input name="CustTitle" size="10" maxlength="10" value="" type="Text">
        </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Address:</strong></td>
        <td class="smTable">
            <input name="CustAddr" size="25" maxlength="100" value="" type="Text">
            <input name="PrefContact" value="A" type="radio">
            Preferred Contact Channel </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Suburb:</strong></td>
        <td class="smTable">
            <input name="CustSub" size="25" maxlength="100" value="" type="Text">
            <input name="CustPostCode" size="4" maxlength="4" value="" type="Text">
            <input class="Button" value="Find" onclick="FindSub('');" type="Button">
        </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Email:</strong></td>
        <td class="smTable">
            <input name="CustEmail" size="25" maxlength="50" value="" type="Text">
            <input name="PrefContact" value="E" type="radio">
            Preferred Contact Channel </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Home Phone Number:</strong></td>
        <td class="smTable">
            <input name="CustHomePh" size="20" maxlength="20" value="" type="Text">
            <input name="PrefContact" value="H" checked="" type="radio">
            Preferred Contact Channel </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Work Phone Number:</strong></td>
        <td class="smTable">
            <input name="CustWorkPh" size="20" maxlength="20" value="" type="Text">
            <input name="PrefContact" value="W" type="radio">
            Preferred Contact Channel </td>
    </tr>
    <tr>
        <td class="TableHead"><strong>Mobile Number:</strong></td>
        <td class="smTable">
            <input name="CustMobPh" size="20" maxlength="20" value="" type="Text">
            <input name="PrefContact" value="M" type="radio">
            Preferred Contact Channel </td>
    </tr>

2 个答案:

答案 0 :(得分:0)

使用浏览器安全性,这是一个命中或未命中选项。我知道你想要什么,但有些浏览器不允许这样做是一个安全问题。

答案 1 :(得分:0)

我确信这不是最有说服力的解决方案,但它符合我的需求。

  

无标题 - 消息(HTML)&lt;可以被任何窗口标题替换,并且是从中复制数据的位置。 &GT;的火狐&LT;是要发布到的窗口(因此有一个单独的IE脚本)。

由于字段为空,清除剪贴板以解决任何问题需要以下内容:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True

由于键击超过处理器而导致SendKeys行为的一些问题导致结果不一致和不可预测。这是通过&gt; WScript.Sleep 100 &lt;线之间的命令。完整的脚本:

Set Shell = WScript.CreateObject("WScript.Shell")
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 2}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.SendKeys "{BACKSPACE 8}"
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.SendKeys "{BACKSPACE 5}"
WScript.Sleep 100
Shell.SendKeys "{LEFT 2}"
WScript.Sleep 100
Shell.SendKeys "{BACKSPACE 3}"
WScript.Sleep 100
Shell.SendKeys "{RIGHT 2}"
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.SendKeys "{LEFT 4}"
WScript.Sleep 100
Shell.SendKeys "{BACKSPACE 6}"
WScript.Sleep 100
Shell.SendKeys "{RIGHT 4}"
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 4}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys "{TAB 2}"
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 12}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 10}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys "{TAB 2}"
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys "{TAB 4}"
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 7}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.SendKeys "{TAB}"
WScript.Sleep 100
Shell.SendKeys "{ENTER}"
WScript.Sleep 100
Shell.AppActivate("Untitled - Message (HTML)")
WScript.Sleep 100
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("+{TAB}")
WScript.Sleep 100
Shell.SendKeys ("^c")
WScript.Sleep 100
Shell.AppActivate"Firefox"
WScript.Sleep 100
Shell.SendKeys "{TAB 5}"
WScript.Sleep 100
Shell.SendKeys ("^v")'Paste
WScript.Sleep 100
Shell.SendKeys "{TAB 3}"
WScript.Sleep 100
Shell.SendKeys "PAX requested no response"