I am looking to implement dragging a div
outside the browser window and it creating a new window with the div
in it.
Whilst my code probably isn’t perfect, I can do that with this:
let dragged = null;
let dropTarget = null;
document.addEventListener("dragstart", e => dragged = e.target);
document.addEventListener("dragend", e => {
if (dropTarget == null) {
const w = window.open("", "_blank", `height=200,width=200,left=${e.screenX},top=${e.screenY},toolbar=0,location=0,menubar=0`);
w.document.body.appendChild(dragged);
}
});
document.addEventListener("dragenter", e => dropTarget = e.target);
document.addEventListener("dragleave", e => {
if (dropTarget == e.target) {
dropTarget = null;
}
});
<div draggable="true">Draggable div</div>
When dragging outside the window onto the desktop, the cursor icon is not-allowed
.
If there is anyway I can trick the browser into thinking the drop is allowed (with a better icon) without actually performing a drop, but instead opening the new window?