gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 19:15:41 33 4
gpt4 key购买 nike

第一次发帖,网站的长期读者。我搜索了整个 Internet,找不到可行的解决方案,而且我尝试了很多重写,但无法修复它。

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

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

要记住的一件事是我是自学成才的,只为工作制作这些。所以不要对我说 super 技术,我不会明白的。如果可能的话,请重写所需的部分,并让我知道代码中发生的原因和情况,以便我能够掌握这个概念,并能够在我学习和成长的过程中使用它/修改它。

代码如下:

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

最佳答案

那是很多代码。有什么意义吗?

这是读取剪贴板的方法,写入剪贴板的方法类似。 HTA 是没有安全性的 IE 窗口,因此您不需要导航。

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

来自帮助

clipboardData Object Members


Provides access to predefined clipboard formats for use in editing operations.

Methods

clearData , getData , setData

关于javascript - HTA:尝试将各种输入框和文本区域写入文本文件并复制到剪贴板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35543112/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com