I only found one HTML element, the IFRAME, that works as a target for
DandD - and succeeded in getting it to receive and display the item (a
powerpoint presentation fragment) by setting the 'application'
property to TRUE. Unfortunately, this does not solve my problem as I
cannot get access through DHTML to the *dynamic* source of the content
of the frame. I assume it is a security feature - that I thought
might be relaxed in an HTA, but if it is, I haven't figure out how to
make it happen.
What I need more that the content of the file is the path to the local
content (fully qualified filespec).
Does anyone know of a readily available object/method/technique that
would allow a scripted application to receive the path from a file
reference dropped from explorer onto a running HTA? Or am I wasting
my time looking. I've done google.group searches, but have come up
empty so far. The best I have been able to do is use a registry hack
to add my application to the PowerPoint file definition so it can be
called from the right-click context menu. It's OK, but I want to
offer the application to a few other users who might find the hack a
bit awkward. The drag-and-drop would be cleaner, I think.
Thanks,
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Hi Tom,
If you use a VBScript to open the IE window, I think you can get what
you want. Each time the URL changes, your script will have to get a
new document object from the IE object, which will contain the new
information.
You might want to create the IE object with event handlers that can
let your script know whenever a new URL is completely loaded, so that
it can get the new document object.
-Paul Randall
I assume you have googled this. Even so, take a look at
this page, entitled "Drag and Drop in Internet Explorer":
http://www.webreference.com/programming/javascript/dragdropie/
This page claims that D&D was available in IE5, and for
arbitrary tags (if I read correctly). Then go to this page
where there is an example:
http://www.webreference.com/programming/javascript/dragdropie/Example1.htm
O.K. On that page you are supposed to be able to drag some
text from the textbox and drop it on the red square. I tried
that and couldn't get it to work (not so promising). However,
I then attempted to drag a file off the desktop and drop it
on the red spot. What happened then was that IE displayed the
file (some basic code with a "bas" extension), and showed the
FULL PATH in the navigation bar. So at least in that respect
IE was able to detect the drop, retrieve the file path, and
retrieve the file too.
I didn't bother to look at the code, but the description claimed
that the javascript was in effect changing a div element into
a drop target. Happy Hunting.
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
I think what you found is a wild goose chase and the
author didn't understand what they were doing. Dragging
from the red square to the INPUT works fine for me in
Firefox with script disabled... because there is no script.
The "Drop" sub called in the OnDrop event is just coded
to show a msgbox that says, "Dropped!"
In other words, a source element can be dropped onto
a destination element when relevant, but that's part of
the HTML operation rather than OLE drag/drop.
Dropping onto the IE window is OLE drag/drop, but it
just loads the file. That is, it's dropping onto IE rather
than onto the document.
OK, that was my experience, following the two postings. I was
preparing a follow-up to that effect when I checked and found your
response.
I might be able to open another window from my application and grab
the URL as Paul suggested (using oIE.locationURL, not
oIE.document.URL), but that's still not quite what I had in mind.
Thanks for the input,
OK, I found a solution. I needed to reference the IFrame location
thus ...
FrameName.location.href
I also found that the common events, like ondrop, etc are not
implemented for an iframe, so I had to use a recursive setTimeout to
poll for a change in the href contents. A basic example is ...
<html><head><title>D&D_Test</title>
<HTA:APPLICATION
ID="objHTADandDTest" APPLICATIONNAME="D&D_Test"
SCROLL="no" SINGLEINSTANCE="yes" WINDOWSTATE="normal"
>
</head>
<SCRIPT Language="VBScript">
Dim g_href
Sub Initiate
g_href = InBox.location.href
setTimeout "readit", 50, "vbscript"
End Sub
sub readit
if inBox.location.href <> g_href then
aPath = split(replace(unescape(inBox.location.href),
"file:///",""),"/")
frame1.innerHTML = "<iframe name=""InBox""" _
& "src=""about:<body>Drop Here</body>""" _
& "height=50px width=100px scrolling=no " _
& "application=yes></iframe>"
showname.innertext = Split(aPath(Ubound(aPath)), ".")(0)
g_href = inBox.location.href
end if
setTimeout "readit", 50, "vbscript"
end sub
</SCRIPT>
<body onload=initiate>
Drag and Drop test<br>
<span id=frame1>
<iframe name="InBox" height=50px width=100px application=yes
scrolling=no src="about:<body>Drop Here</body>"></iframe></span>
<span id=showname height=25px></span>
<br><br>
</body></html>
It will still pop-up an Open/Save/Cancel dialog when the first file is
dropped. In my case, with PPT files, I marked the dialog to always
open the file and the dialog never reappears. I suppose it isn't
entirely safe to do that, since PowerPoint files can have macros, but
I doubt it's a common mode of attack, so I chanced it for now. My
intent is to find out how to set/reset that selection in the registry,
but I haven't done the search for the registry location yet. (Can
someone provide that? - Thanks)
BTW, I found the necessary corrective (along the lines of Paul's early
response) with an MSDN search on the HTMLwindow2 window type that an
IFRAME returns. This led to the realization that I needed to treat
the frame like a window, though many of the normal attributes/
properties/events don't apply (aren't supported).
I'm glad to hear that my post was helpful. Your name has been in my
GoogleGroups.HTA preferred author list for many years.
-Paul Randall
I'm honored and a little flattered.
BTW, as a followup I found the solution to the "File Download" Open/
Save/Cancel dialog issue in the form of the EditFlag setting for the
executable file registry setting. I set the flag to &h00010000& at
initiation ...
sub initiate
g_href = InBox.location.href
with createobject("wscript.shell")
g_nFlags = .regread(skey) ' save current condition (probably 0)
.regwrite skey, &h00010000&, "REG_DWORD"
end with
setTimeout "readit", 50, "vbscript"
end sub
and reset it at onbeforeunload ...
sub restore
with createobject("wscript.shell")
.regwrite skey, g_nFlags, "REG_DWORD"
end with
end sub
I simply set <body onload=iniitate onbeforeunload=restore>. The
variable skey points to the appropriate executable's file handler
class in the registry.
It's all coming together.
Again, thanks for the help.
Yuch! I hate polling.
OK, this is good thread which I'm seeing too late, but here
are a few additional comments:
Isn't your iterated setTimeout (it's not recursive, after all)
really just a setInterval?
More importantly, for an event driven approach, what you
could possibly do, is to identify the IE that you're in (not
sure if you're given the handle - in case not, first set a
random value top.identifier = randomValue and then
iterate through all IEs looking for the one which
matches). Once you've done that, you could then set an
event handler onto IE's BeforeNavigate2 event, and
that event handler should provide you the file name (and
the possibility to redirect, should you wish). This is
one of the few events where MS is nice enough to let
you know what frame it correlates to.
Csaba Gabor from Vienna
Finally, here's an old thread on a different aspect of
drag and drop. I don't see that it's relevant to your
situation, but perhaps has some interesting ideas.
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/a7d2c9fa091dd0fc/
Me too. As I said, I tried events, but the only two that were
implemented were onfocus and onblur, neither of which seemed to work
when I dropped a file on them. Plus, any port in a storm is fine with
me - I just don't mind clumsy if it gets the job done and isn't too
hard to understand (that's a more recent development - in DOS days
gone by I used 'inconceivable' hacks all the time).
> OK, this is good thread which I'm seeing too late, but here
> are a few additional comments:
>
> Isn't your iterated setTimeout (it's not recursive, after all)
> really just a setInterval?
Yes, I suppose I could have used the setInterval, but I find having to
use a global variable to hold the pointer to the interval timer a
nuisance. I have since developed an approach that clears the frame
from the document and replaces it with a span that looks just like the
original, but displays the file's name as if it were dropped into an
input box. Once I replace the frame, I turn off the polling and use
event trapping for any further processing (like erasing the input on a
double-click).
> More importantly, for an event driven approach, what you
> could possibly do, is to identify the IE that you're in (not
> sure if you're given the handle - in case not, first set a
> random value top.identifier = randomValue and then
> iterate through all IEs looking for the one which
> matches). Once you've done that, you could then set an
> event handler onto IE's BeforeNavigate2 event, and
> that event handler should provide you the file name (and
> the possibility to redirect, should you wish). This is
> one of the few events where MS is nice enough to let
> you know what frame it correlates to.
>
> Csaba Gabor from Vienna
>
> Finally, here's an old thread on a different aspect of
> drag and drop. I don't see that it's relevant to your
> situation, but perhaps has some interesting ideas.http://groups.google.com/group/microsoft.public.scripting.vbscript/br...
I'm working in an HTA, not IE. But I'll explore BeforeNavigate2 has
any applicability. Thanks.
This is a good point. I also dislike globals. One possibility is to
put
the pointer onto the function itself, since a function is an object
and
can take arbitrary properties.
myfunc.intervalPtr = window.setInterval (myfunc, ...)
Nevertheless, to tell the truth, I never use setInterval myself.
Rather, I always use the technique you illustrated with the
iterated setTimeouts. It was actually a subtle dig on the use
of the word recursive (which I see far too often).
> from the document and replaces it with a span that looks just like the
> original, but displays the file's name as if it were dropped into an
> input box. Once I replace the frame, I turn off the polling and use
> event trapping for any further processing (like erasing the input on a
> double-click).
>
> > More importantly, for an event driven approach, what you
> > could possibly do, is to identify the IE that you're in (not
> > sure if you're given the handle - in case not, first set a
> > random value top.identifier = randomValue and then
> > iterate through all IEs looking for the one which
> > matches). Once you've done that, you could then set an
> > event handler onto IE's BeforeNavigate2 event, and
> > that event handler should provide you the file name (and
> > the possibility to redirect, should you wish). This is
> > one of the few events where MS is nice enough to let
> > you know what frame it correlates to.
>
> >Csaba Gabor fromVienna
>
> > Finally, here's an old thread on a different aspect of
> > drag and drop. I don't see that it's relevant to your
> > situation, but perhaps has some interesting ideas.http://groups.google.com/group/microsoft.public.scripting.vbscript/br...
>
> I'm working in an HTA, not IE. But I'll explore BeforeNavigate2 has
> any applicability. Thanks.
I just want to make sure I'm not misunderstanding something here
(never having used an .hta before - I didn't want to start using yet
another 3 letter suffix). I always thought .hta's were browser pages
that IE hosted with security restrictions diminished. If that's the
case, there must be an associated IE that one can get to through
CreateObject("Shell.Application").Windows (unless run as another
user, etc.). Whether the .hta will allow you access to
Shell.Application
is something I don't know, but vbscript (and php) certainly do
(provided
it's not under a web server). If you can spot a misunderstanding
here,
it'd be great if you'd point it out.
Best,
Csaba
OK, your point is correct. I'll police my use of the word 'recursive'
in the future.
Regarding HTAs: They are not hosted by IE, but by mshta.exe, which
obviously makes use of most of the same components as IE, but does not
itself provide a COM interface AFAIK.
Tom Lavedas
Some examples that may be of interest.
Note: requires adding hta drag/drop handler info to registry
http://www.jensign.com/JavaScience/www/wsh/scriptlister/index.html
http://www.jensign.com/JavaScience/www/wsh/imager/index.html