Drag & drop across frames with jQuery UI

我的未来我决定 提交于 2019-12-23 02:46:14

问题


I would like to do this:

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

  • Drop this DIV element 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?


回答1:


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.



来源:https://stackoverflow.com/questions/3075696/drag-drop-across-frames-with-jquery-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!