Google Answers Logo
View Question
 
Q: Drag and Drop Objects/URLs to Browsers ( No Answer,   0 Comments )
Question  
Subject: Drag and Drop Objects/URLs to Browsers
Category: Computers > Programming
Asked by: rosenblumj-ga
List Price: $20.00
Posted: 13 Aug 2005 10:26 PDT
Expires: 06 Sep 2005 13:08 PDT
Question ID: 555331
Is it possible to capture Drag and Drop events in modern browsers, and
if so, how? Specifically, I want to be able to drag images and URLs
from one browser window to another, and then capture data about the
dropped object (specifically, it's URL).

What I've learned so far is that if you have a form field (input
type=text, or textarea), AND that field has the focus, then you can
drag an object to it, and that field will be populated by the URL of
the dragged object (By the nature of this task, the target window does
not have the focus when you begin to drag). This seems to work
cross-browser and cross-platform.

This has serious limitations: 1) you can only drop to one field (the
field that has focus when you leave the page) and 2) there needs be a
field with focus on it for this to work. This is not satisfactory for
my task, so I want to know if I can generically capture this
information without having a field with the focus. I've also found
that window.ondragdrop doesn't seem to work.

The successful answer will either 1) prove with sufficient citations
(1 reputable source would be fine) that this is NOT possible (outside
of what I've already discovered) or 2) provide runnable
cross-browser/cross-platform code example of how this can be done.

Here is an example of code (this requires the prototype.js library,
which you can find easily on google) that will pop up an alert if
something is dragged to a focused field:

<html>
    <head>
        <title>test</title>
        <script  type="text/javascript">
        function alertName (evt) {
            var r = '';
            for (var i = 0; i < evt.data.length; i++) {
                r += i + ': ' + evt.data[i] + '\n';
            }
            alert(r);
            return false;
        }
        </script>
        <script src="prototype.js" type="text/javascript"></script>
        
        <style>
            .supertext textarea {color:blue; background:gray; }
        </style>
    </head>
    <body>
<!-- a href="#" onclick="javascript:window.open('links.htm',null,'height=250,width=150,status=yes,toolbar=no');">click</a
-->
<form id="thing">
    <span class="supertext">
    <input type="text" id="testy" rows="50" cols="100" value="" />
    </span>
    <input type="checkbox"/>
</form>
        <script type="text/javascript">
            new Form.Element.Observer('testy', 1.0, function(element,
value) { alert(value); } );

//          alert(Prototype.Version);
// onDrop="alert(document.forms[0].testy.value);"
onMouseOver="document.forms[0].testy.focus();"
           this.onDragDrop = new function (evt) { return false; }
        </script>
    </body>

</html>
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy