简体   繁体   English

如何使用(IE)DOM修改网页以添加表单元素和JavaScript?

[英]How can I modify a web page using (IE )DOM to add Form Elements and JavaScript?

I have 3rd party application (compiled) that can read data from an HTML page. 我有第三方应用程序(已编译),可以从HTML页面读取数据。 This is done by creating an Internet Explorer object and loading an empty page (.navigate "about:blank"). 这是通过创建Internet Explorer对象并加载空页(.navigate“about:blank”)来完成的。 Form element are added to the page via Document.Body.innerHTML. 表单元素通过Document.Body.innerHTML添加到页面中。 When exiting the HTML page via Submit the application reads the submission data via CreateObject("WScript.Shell"). 通过提交应用程序退出HTML页面时,通过CreateObject(“WScript.Shell”)读取提交数据。 I would like to add some JavaScript to combine input data in to a string. 我想添加一些JavaScript来将输入数据合并到一个字符串中。 That is, data input into input text box 1 and input text box 2 are joined in text box 3 OR/AND change the values in textbox 3 based on check boxes or radio buttons. 也就是说,输入到输入文本框1和输入文本框2的数据在文本框3中连接,或者根据复选框或单选按钮改变文本框3中的值。 I could then send these values back to the application. 然后我可以将这些值发送回应用程序。 How can I further modify this empty web page to include java script to accomplish the above 如何进一步修改此空网页以包含java脚本来完成上述操作

The "g_objIE.Document.Body.innerHTML = " code works just fine. “g_objIE.Document.Body.innerHTML =”代码工作得很好。 It is very basic and just includes form elements. 它非常基础,只包含表单元素。 Can I simply add java script to innerHTML? 我可以简单地将java脚本添加到innerHTML吗? I don't think so. 我不这么认为。 I tried adding very basic code and received a 'expecting end of statement' error. 我尝试添加非常基本的代码并收到“期待语句结束”错误。 I was attempting to insert: " 我试图插入:“

" & _ " document.getElementById("demo").innerHTML = 5 + 6; “&_”document.getElementById(“demo”)。innerHTML = 5 + 6; "& _ “&_

This is the working code. 这是工作代码。

 ' First step, set up the dialog (InternetExplorer) Set g_objIE = CreateObject("InternetExplorer.Application") g_objIE.Offline = True g_objIE.navigate "about:blank" g_objIE.document.focus() ' Wait for the navigation to the "blank" web page to complete Do crt.Sleep 900 Loop While g_objIE.Busy g_objIE.Document.body.Style.FontFamily = "Sans-Serif" ' Here's where we "create" the elements of our dialog box. We basically ' throw HTML into the document, and IE loads it in real-time for us. ' ' The hidden "ButtonHandler" input is used to tie IE and ' SecureCRT together such that SecureCRT can know when a ' button is pressed, etc. g_objIE.Document.Body.innerHTML = _ "<input type=radio name='LogMode' value='Append' AccessKey='A' checked>fpeth.3125 / Access" & _ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;" & _ "<input type=radio name='LogMode' value='Overwrite' Accesskey='w' >fpeth.3070 / Core<br>" & _ "<hr>" & _ "<b>Path/File</b>&nbsp;&nbsp;<input name='fName' size='60' maxlength='60' tabindex=1><br>" & _ "<b>HOST</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name='tID' size='30' maxlength='30'><br>" & _ "<hr>" & _ "<button name='Cancel' AccessKey='C' onclick=document.all('ButtonHandler').value='Cancel';><u>C</u>ancel</button>" & _ "<input name='ButtonHandler' type='hidden' value='Nothing Clicked Yet'>" g_objIE.MenuBar = False g_objIE.StatusBar = True g_objIE.AddressBar = False g_objIE.Toolbar = False g_objIE.height = 270 g_objIE.width = 510 g_objIE.document.Title = "TCP" g_objIE.Visible = True 
  1. You'll want to control the HTML header and doctype of your document, which means you'll need to use document.write instead of body.innerHTML . 您需要控制文档的HTML标头和doctype,这意味着您需要使用document.write而不是body.innerHTML As well as making scripts work, this will give you control of the HTML head and doctypes. 除了使脚本有效之外,还可以控制HTML头文件和文档类型。
  2. To make things easier to maintain, use a variable to hold your HTML string 为了使维护更容易,请使用变量来保存HTML字符串
Dim htmlString
htmlString = _
  "<!doctype html>" & _
  "<html>" & _
  "<head><title>tcp</title></head>" & _
  "<body>" & _
  "<input type=radio name='LogMode' value='Append' AccessKey='A' checked>fpeth.3125 / Access" & _
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;" & _
        "<input type=radio name='LogMode' value='Overwrite' Accesskey='w' >fpeth.3070 / Core<br>" & _
    "<hr>" & _
    "<b>Path/File</b>&nbsp;&nbsp;<input name='fName' size='60' maxlength='60' tabindex=1><br>" & _
    "<b>HOST</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name='tID' size='30' maxlength='30'><br>" & _
    "<hr>" & _
    "<button name='Cancel' AccessKey='C' onclick=document.all('ButtonHandler').value='Cancel';><u>C</u>ancel</button>" & _
    "<input name='ButtonHandler' type='hidden' value='Nothing Clicked Yet'>" & _
    "<div id=demo>goes here</div>" & _
    "<script> " & _
    "   document.getElementById('demo').innerHTML = (5 + 6).toString(); " & _
    "</script>" & _
    "</body>" & _
    "</html>"

g_objIE.document.write(htmlString)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在处理 DOM 之前使用谷歌浏览器内容脚本修改 web 页面? - How can I modify a web page using google chrome content script before the DOM is processed? 如何使用 JavaScript DOM 向网页上的 HTML 元素添加文本 - How to add text to HTML element on web page using JavaScript DOM 如何使用JavaScript将jQuery添加到我的网页? - How can I add jQuery to my web page using Javascript? 如何使用javascript移动多个DOM元素? - How can I move multiple DOM elements using javascript? 使用 JavaScript 在 web 页面上对存储桶中的 DOM 元素进行排序的最佳方法 - Best way to sort DOM elements in buckets on a web page using JavaScript 使用 JavaScript 向 DOM 添加元素 - add elements to the DOM using JavaScript 如何使用javascript或jquery将元素动态添加到表单中? - how can i dynamically add elements to my form using javascript or jquery? 如何通过JavaScript获取DOM元素属性名称,假设点击可以在页面的任何位置? - How can I get DOM elements attributes name on a click, by JavaScript supposing the click can be anywhere on the page? 如何将DOM元素保存在javaScript对象中? 我想通过更新对象来更新页面 - How can I save DOM elements inside of a javaScript object? I want to update the page by updating the object 如何在不使用 ID 标签的情况下将悬停文本添加到 Javascript 中的现有网页? - How can I add hover-over text to an existing web page in Javascript without using ID tags?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM