Drag and drop - is it possible to get the url?

I implemented a simple drag and drop. The main goal is to drag images from the browser. Is it possible for me to get the URL from which this image was transferred?

So let's say I'm on SO and I'm dragging a logo. Is there any way to find out what it was from /qaru.site / ... ? Thanks

+5
source share
1 answer

For images that are not also links, the following code will register the URL from which the image was dragged. This works for me in Safari and Firefox.

@implementation DragView

- (void)awakeFromNib {
    [self registerForDraggedTypes:[NSArray arrayWithObject:NSURLPboardType]];
}

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
    return NSDragOperationCopy;
}

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
    NSPasteboard *pboard;    
    pboard = [sender draggingPasteboard];

    NSLog(@"types: %@", [pboard types]);
    NSLog(@"url: %@", [NSURL URLFromPasteboard:pboard]);

    return YES;
}

@end

, URL- href . URL- "" ( "Finder Get Info" ) kMDItemWhereFroms .

+5

All Articles