Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTA:尝试将各种输入框和文本区域写入文本文件并复制到剪贴板_Javascript_Vbscript_Clipboard_Copy Paste_Hta - Fatal编程技术网

Javascript HTA:尝试将各种输入框和文本区域写入文本文件并复制到剪贴板

Javascript HTA:尝试将各种输入框和文本区域写入文本文件并复制到剪贴板,javascript,vbscript,clipboard,copy-paste,hta,Javascript,Vbscript,Clipboard,Copy Paste,Hta,第一篇文章在这里,长期阅读该网站。我搜索了整个互联网,找不到一个有效的解决方案,我尝试了多次重写,但都无法修复 我为工作编写HTA文件。通常是特定于部门的笔记工具,使他们的工作更轻松。除了复制/粘贴外,我所有需要的东西都在工作。我从我编写的另一个工具复制了“复制/粘贴”部分,它可以工作,但忽略了\r\n,我一直对此有问题,因此我希望用更可靠的工具替换整个部分。所以我想,如果我可以只写一个文本文件,然后将该文本文件复制到剪贴板上,那就太完美了。因为这也会给他们“Oops,我不是想通过加载创建的文本

第一篇文章在这里,长期阅读该网站。我搜索了整个互联网,找不到一个有效的解决方案,我尝试了多次重写,但都无法修复

我为工作编写HTA文件。通常是特定于部门的笔记工具,使他们的工作更轻松。除了复制/粘贴外,我所有需要的东西都在工作。我从我编写的另一个工具复制了“复制/粘贴”部分,它可以工作,但忽略了\r\n,我一直对此有问题,因此我希望用更可靠的工具替换整个部分。所以我想,如果我可以只写一个文本文件,然后将该文本文件复制到剪贴板上,那就太完美了。因为这也会给他们“Oops,我不是想通过加载创建的文本文件来清除该文本”选项,以查看他们点击了什么。我还计划在clear按钮上实现相同的“oops”,这样它将写入文件,然后清除输入框以保持oops文件仍然存在

要快速回顾,Write按钮工作得很好,Clear也可以(但需要写入oops文件),Copy按钮需要完全重写。如果可能的话,我想保留所有的VBScript,因为我认为目前为止我的问题源于两种代码类型,以及我将旧代码复制/粘贴到新工具中的问题

要记住的一件事是,我自学成才,只为工作而做。所以不要对我过分技术化,我不会理解的。如果可能,请重新编写所需的部分,并让我知道代码中发生的原因和情况,以便我能够掌握概念,并能够在将来随着我的学习和成长使用/修改它

代码如下:

<hta:application
icon="#"
border="thin"
borderStyle="static"
caption="yes"
innerBorder="no"
maximizeButton="no"
minimizeButton="yes"
navigable="no"
scroll="no"
scrollFlat="yes"
singleInstance="yes"
showInTaskbar="yes"
windowState="normal"
contextMenu="no"
version="1.0"
>

<!DOCTYPE html>
<HTML><HEAD><TITLE>Note Tool</TITLE>

<style type='text/css'>
</style>

</head> 

<SCRIPT LANGUAGE="VBScript">
Function Writer_OnClick()

    UserID = (Document.getElementByID("OB1").Value)
    ContactName = (Document.getElementByID("OB2").Value)
    ExternalNotes = (Document.getElementByID("OB3").Value)
    InternalNotes = (Document.getElementByID("OB4").Value)
    CSKBRef = (Document.getElementByID("OB5").Value)

    Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("html01.txt",1)
    HTML01 = objFileToRead.ReadAll()
    objFileToRead.Close
    Set objFileToRead = Nothing

    Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("html02.txt",1)
    HTML02 = objFileToRead.ReadAll()
    objFileToRead.Close
    Set objFileToRead = Nothing

    Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("html03.txt",1)
    HTML03 = objFileToRead.ReadAll()
    objFileToRead.Close
    Set objFileToRead = Nothing

    Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("html04.txt",1)
    HTML04 = objFileToRead.ReadAll()
    objFileToRead.Close
    Set objFileToRead = Nothing

    Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("html05.txt",1)
    HTML05 = objFileToRead.ReadAll()
    objFileToRead.Close
    Set objFileToRead = Nothing

    Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile("poop.html",2,true)
    objFileToWrite.WriteLine(HTML01)
    objFileToWrite.WriteLine(UserID)
    objFileToWrite.WriteLine "</li><li>Contacts: "
    objFileToWrite.WriteLine(ContactName)
    objFileToWrite.WriteLine(HTML02)
    objFileToWrite.WriteLine(ExternalNotes)
    objFileToWrite.WriteLine(HTML03)
    objFileToWrite.WriteLine(InternalNotes)
    objFileToWrite.WriteLine(HTML04)
    objFileToWrite.WriteLine(CSKBRef)
    objFileToWrite.WriteLine(HTML05)
    objFileToWrite.Close
    Set objFileToWrite = Nothing
End Function
</SCRIPT>

<script language="VBScript">
    Sub ClearText
       User.Value = "" 
       Contact.Value = "" 
       ExternalNotes.Value = "" 
       InternalNotes.Value = "" 
       CSKB.Value = "" 
    End Sub
</script>

<SCRIPT LANGUAGE="JavaScript">
    function RestoreWindowSize()
    {
    window.resizeTo(750, 420);
    }
</script>

<SCRIPT LANGUAGE="JavaScript">
var desc = new Array();
desc['OB1'] = 'User ID';
desc['OB2'] = 'Contact Name';
desc['OB3'] = 'External Notes';
desc['OB4'] = 'Internal Notes';
desc['OB5'] = 'CSKB Topic';

function CopyFields(){
    var copytext = '';
    for(var i = 0; i < arguments.length; i++){
        copytext += desc[arguments[i]] + ': ' + document.getElementById(arguments[i]).value + '\r\n';
    }
    var tempstore = document.getElementById(arguments[0]).value;
    document.getElementById(arguments[0]).value = copytext;
    document.getElementById(arguments[0]).focus();
    document.getElementById(arguments[0]).select();
    document.execCommand('Copy');
    document.getElementById(arguments[0]).value = tempstore;
}
</script>


<body onload="RestoreWindowSize()">

User ID: <input type="text" name="User" id="OB1"><br>
Contact Name: <input type="text" name="Contact" id="OB2"><br>
External Notes: <textarea rows="5" cols="68" type="text" name="ExternalNotes" id="OB3"></textarea><br>
Internal Notes: <textarea rows="5" cols="68" type="text" name="InternalNotes" id="OB4"></textarea><br>
KB Reference(s): <input type="text" name="CSKB" id="OB5"><br>

<br><br>
<input type="button" onClick="ClearText" value="Clear Me">
<input type="button" name="Copier" value="Copy Me" onClick="CopyFields 'OB1', 'OB2', 'OB3', 'OB4', 'OB5'">
<input type="button" name="Writer" value="Write Me">


</body> 
</html> 

注释工具
函数编写器_OnClick()
UserID=(Document.getElementByID(“OB1”).Value)
ContactName=(Document.getElementByID(“OB2”).Value)
ExternalNotes=(Document.getElementByID(“OB3”).Value)
InternalNotes=(Document.getElementByID(“OB4”).Value)
CSKBRef=(Document.getElementByID(“OB5”).Value)
设置objFileToRead=CreateObject(“Scripting.FileSystemObject”).OpenTextFile(“html01.txt”,1)
HTML01=objFileToRead.ReadAll()
objFileToRead。关闭
设置objFileToRead=Nothing
设置objFileToRead=CreateObject(“Scripting.FileSystemObject”).OpenTextFile(“html02.txt”,1)
HTML02=objFileToRead.ReadAll()
objFileToRead。关闭
设置objFileToRead=Nothing
设置objFileToRead=CreateObject(“Scripting.FileSystemObject”).OpenTextFile(“html03.txt”,1)
HTML03=objFileToRead.ReadAll()
objFileToRead。关闭
设置objFileToRead=Nothing
设置objFileToRead=CreateObject(“Scripting.FileSystemObject”).OpenTextFile(“html04.txt”,1)
HTML04=objFileToRead.ReadAll()
objFileToRead。关闭
设置objFileToRead=Nothing
设置objFileToRead=CreateObject(“Scripting.FileSystemObject”).OpenTextFile(“html05.txt”,1)
HTML05=objFileToRead.ReadAll()
objFileToRead。关闭
设置objFileToRead=Nothing
设置objFileToWrite=CreateObject(“Scripting.FileSystemObject”).OpenTextFile(“poop.html”,2,true)
objFileToWrite.WriteLine(HTML01)
objFileToWrite.WriteLine(用户ID)
objFileToWrite.WriteLine“
  • 联系人: objFileToWrite.WriteLine(联系人姓名) objFileToWrite.WriteLine(HTML02) objFileToWrite.WriteLine(外部注释) objFileToWrite.WriteLine(HTML03) objFileToWrite.WriteLine(内部注释) objFileToWrite.WriteLine(HTML04) objFileToWrite.WriteLine(CSKBRef) objFileToWrite.WriteLine(HTML05) objFileToWrite。关闭 设置objFileToWrite=Nothing 端函数 次明文 User.Value=“” Contact.Value=“” ExternalNotes.Value=“” InternalNotes.Value=“” CSKB.Value=“” 端接头 函数RestoreWindowSize() { 窗口。resizeTo(750420); } var desc=新数组(); desc['OB1']='User ID'; desc['OB2']=“联系人姓名”; desc['OB3']=“外部注释”; desc['OB4']='internalnotes'; desc['OB5']=“CSKB主题”; 函数CopyFields(){ var copytext=''; for(var i=0;i 联系人姓名:
    外部注释:
    内部注释:
    KB参考资料:



  • 这是一大堆代码。这有什么意义吗

    这是如何读取剪贴板,写入它是类似的。HTA是没有安全性的IE windows,因此您不需要导航

    Sub Clip
        Set ie = CreateObject("InternetExplorer.Application") 
        ie.Visible = 0
        'Have to navigate to a local file to put IE into Intranet Zone, else this will generate security dialog asking permission
        ie.Navigate2 FilterPath & "Filter.html"
        Do 
            wscript.sleep 100
        Loop until ie.document.readystate = "complete"  
        txt=ie.document.parentwindow.clipboardData.GetData("TEXT")
        ie.quit
        If IsNull(txt) = true then 
            outp.writeline "No text on clipboard"
        else
            outp.writeline txt
        End If
    End Sub
    
    从帮助

    剪贴板数据对象成员


    提供对用于编辑操作的预定义剪贴板格式的访问

    方法

    clearData、getData、setData

    诸如此类:

    <SCRIPT LANGUAGE="VBScript">
    Dim desc,ID
    desc = Array("User ID","Contact Name","External Notes","Internal Notes","CSKB Topic")
    ID = Array("OB1","OB2","OB3","OB4","OB5")
    Function CopyFields()
    Dim copytext,i
        copytext = ""
        For i = LBound(desc) to UBound(desc)
            copytext = copytext & desc(i) & " : " & document.getElementById(ID(i)).value & vbcrlf
        Next
        Msgbox copytext
        document.parentwindow.clipboardData.SetData "text",copytext
    End Function
    </script>
    
    
    Dim desc,ID
    desc=数组(“用户ID”、“联系人姓名”、“外部注释”、“内部注释”、“CSKB主题”)
    ID=数组(“OB1”、“OB2”、“OB3”、“OB4”、“OB5”)
    函数CopyFields()
    暗淡的文字,我
    copytext=“”
    对于i=LBound(desc)到UBound(desc)
    copytext=copytext&desc(i)&“&document.getElementById(ID(i)).value&vbcrlf
    下一个
    Msgbox copytext
    document.parentwindow.clipboardData.SetData“文本”,copytext
    端函数
    
    并将HTML部分更改为:

    <input type="button" name="Copier" value="Copy Me" onClick="CopyFields()">
    
    
    
    您可以看看这个示例,它向您展示了一些有用的函数,可以从文本文件中读取并使用HTA将其加载到文本区域==>感谢Hackoo的回复。我不是试图加载到文本区域,而是接受用户在框中键入的内容,将其写入txt文件并将其复制到剪贴板。它需要写入/复制到separ上的剪贴板