开发者

Drag & drop across frames with jQuery UI

开发者 https://www.devze.com 2023-01-03 20:41 出处:网络
I would like to do this: Drag a DIV element from a first document that contains an IFRAME Drop this DIV elemen开发者_如何学编程t into into a second document, inside the IFRAME.

I would like to do this:

  • Drag a DIV element from a first document that contains an IFRAME

  • Drop this DIV elemen开发者_如何学编程t into into a second document, inside the IFRAME.

Is there a way to use jQuery UI draggable & droppable to achieve this? or otherwise do this in a cross-browser way, possibly with another JS library?


You can easily do this by accessing the contents inside the iframe with jQuery this way:

$( 'your-iframe' ).contents().find( 'elements-to-find' ).droppable();

To make sure the iframe contents are loaded when you run the script, you must wait for the jQuery load event of the iframe.

$('your-iframe').load(function() {

    $( 'your-iframe' ).contents().find( 'elements-to-find' ).droppable();

});

I had the same necessity of you and managed to do drag and drop between iframes this way, and everything worked correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消