识别文件被拖拽到的小程序

发布于 2024-09-08 07:12:09 字数 945 浏览 2 评论 0原文

我使用Java小程序作为上传文件的盒子。从文件系统中选择文件并将它们拖动到小程序上会导致将文件路径名添加到输入文本框中。

目前的设计如下:每个“上传”按钮都被一个用于拖放的小程序、一个单选框和一个输入框包围。每个单选框都有自己的 ID。拖放是使用 java.awt.datatransfer 包中的方法实现的。当用户将文件拖放到所选小程序上时,以下 Java 代码

          getAppletContext().showDocument
            (new URL("javascript:appletUpdateFile()"));
          }

将调用 javascript 函数。一切都很好。但存在以下问题 - 我对所有上传按钮使用一个小程序。它实际上是 CMS 外部用户脚本 (IEPro) 的一部分,因此 CMS 当前页面中的“上传”按钮数量可能非常多。因此,为每个按钮创建唯一的小程序并不是一个可接受的解决方案。

它必须以某种方式确定应该更新哪个输入框(属于某些“上传”按钮/拖放框)。目前它是由单选框确定的。因此,用户需要在小程序上实际拖动文件之前选择特定选项。从用户的角度来看,这一步是多余的。

我想以某种方式识别文件被拖动到哪个小程序而不使用单选框。到目前为止,我已经尝试了几种方法:

1)在小程序的父元素上使用 mouseover、mouseup 等进行识别 - 它可以选择并设置正确的小程序(设置单选框、变量等)。但是它不起作用,因为如果光标持有文件,所有鼠标事件都会被忽略...

2)使用“this”关键字作为 appletUpdateFile() 函数的参数 - 这显然也不起作用,浏览器当然无法确定调用者applet of 'new URL("javascript:appletUpdateFile()'

所以,我希望我输入的内容足以介绍该问题。如果有任何方法(在 applet 方面或在 JavaScript 方面)完成此任务,我将不胜感激。

I am using Java applet as a box for uploading files. Choosing files from file system and dragging them on applet cause adding file pathnames into the input text box.

The design is currently following: Each 'Upload' button is surrounded by an applet for the drag-n-drop, a radio box and an input box. Each radio box has its own id. The drag-n-drop is realised using the methods from java.awt.datatransfer packagee. When user drops file(s) on the chosen applet, following Java code

          getAppletContext().showDocument
            (new URL("javascript:appletUpdateFile()"));
          }

calls javascript function. Everything works just fine. But there is a following problem - I use one applet for all Upload buttons. It's in fact the part of an external user script (IEPro) for CMS, so there might be really high count of 'Upload' buttons in the current page of CMS. Therefore creating unique applet for each button is not an acceptable solution.

It has to be somehow identify which input box (belonging to certain 'Upload' button / drag-n-drop box) should be updated. Currently it's determined by radio boxes. So user needs to select particular option before actual dragging file(s) on applets. From the user point of view this step is redundant.

I would like to somehow identify to which applet were dragged files without using radio boxes. Till now I have tried several approaches:

1) Identify using mouseover, mouseup, etc. on parent elements of applets - it could choose and set the right applet (setting radio box, variable, etc.). However it is not working, because all mouse events are simply ignored if the cursor holds files...

2) Using "this" keyword as an parameter of appletUpdateFile() function - this is clearly also not working, browsers of course cannot determine caller applet of 'new URL("javascript:appletUpdateFile()'

So, I hope I typed enough to introduce the problem. I would be grateful for any way (on the side of applet, or on the JavaScript side) to accomplish this task.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷迭香的记忆 2024-09-15 07:12:09

当您通过 PHP、Javascript 或其他方式生成小程序的对象标记和输入框时,您可以向每个小程序传递一个唯一值(如果它们是在循环中生成的,则候选者将是 $i 的当前值),您可以这样做也用于标识输入框(例如,将“id”属性设置为“inputBox$i”之类的值)。小程序将此值传递给您的 appletUpdateFile 函数,然后该函数可以通过 document.getElementById("inputBox"+idNumber) 访问相应的输入框。

When you are generating the applet's object tag and the input boxes via PHP, Javascript or something else you could pass every applet an unique value (if they are generated in a loop, a candidate would be the current value of $i) which you do also use to identify the input box (e.g. set the "id" attribute to something like "inputBox$i"). The applet passes this value to your appletUpdateFile function, which then may access the corresponding input box via document.getElementById("inputBox"+idNumber).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文