Page 2 of 2

Re: StartDragging doesn't be trigged

Posted: Sun May 16, 2021 1:47 am
by coater
I saw the webs and I am still confused. If I use us I cannot get the drag data(I guess chrome deal with drag itself so when we drag some text or link to input element it will accept the text or link text).
How to get the drag data? So I can judge whether it is a link or text by JS ?
How to know if the text was accepted by the target? So I can operate it if it is not accept by target element.
Thank you!

Re: StartDragging doesn't be trigged

Posted: Mon May 17, 2021 12:58 pm
by salvadordf
Chromium doesn't expose all the information in normal mode.
If you need that information I would suggest to use a browser in OSR mode.

...unless there's a way in JavaScript to intercept that. I'm not a JavaScript expert and I could be wrong.

Re: StartDragging doesn't be trigged

Posted: Tue Jun 08, 2021 9:22 am
by coater

Code: Select all

var Mydroptagetobjint = 0;
var  MyUrlTxt1= "";
var  MyTxt1= "";
document.addEventListener("dragstart", function(event)
	{
       event.dataTransfer.setData("Text", window.getSelection().toString());
       MyTxt1 = window.getSelection().toString();

       if (event.target && event.target.href  ) 
	       {
		       event.dataTransfer.setData("Url",  event.target.href);
		       MyUrlTxt1 = event.target.href;
	       }
	});

document.addEventListener("dragend", function(event)
	{
        if ( Mydroptagetobjint  != 4 ) 
	        {
	        	if ( MyTxt1 !="" )
		        	{
		        		window.open("https://www.baidu.com/s?wd=" + MyTxt1, "_blank");
		        	} else if (  MyUrlTxt1 !="" ) 
			        	{
			        		window.open(MyUrlTxt1, "_blank");
			        	}
	        }
        Mydroptagetobjint = 0;
        MyUrlTxt1= "";
		MyTxt1= "";
	});

document.addEventListener("drop", function(event)
	{
        if (event.target && event.target.tagName && ["TEXTAREA", "INPUT"].includes(event.target.tagName) ) 
		    {
		        Mydroptagetobjint = 4;
		    } 
        else 
        	{
        	  Mydroptagetobjint = 5;
		    }
	});
Thank you!
Now I resolve the problem, but I have another question.
How to accept drag text(url) from another application? Chrome can operate it, but cef4 doesn't.

Re: StartDragging doesn't be trigged

Posted: Wed Jun 09, 2021 8:25 am
by salvadordf
I guess that's a JavaScript question and I'm not an expert, sorry.

Consider using a browser in OSR mode to have full control over drag and drop from Delphi.