Search code examples
javascriptelfinder

Close elfinder Programatically after File selection


I want my elfinder should be closed automatically after file selection.

<script>
    function upload_slider(){
        var f = $('#elfinder').elfinder({
            url : 'plugins/elfinder/php/connector.php',
            height: 490,
            docked: false,
            dialog: { width: 400, modal: true },
            closeOnEditorCallback: true,
            getFileCallback: function(url) {
                $('#new_file').val(url);
                // CLOSE ELFINDER HERE
            }
        }).elfinder('instance');
    }
</script>

<input type="text" id="new_file" />
<input type="button" onclick="upload_slider();" value="Select File"  />
<div id="elfinder"></div>

How to do this? I've searched many places by cant find appropriate way.


Solution

  • After hours i got a solution for you, as I had exactly the same problem. I think its working ok.

    $().ready(function() {
    $('#select-button').click(function(){
        var f = $('#elfinder').elfinder({
            url : 'plugins/elfinder/php/connector.php',
            height: 490,
            docked: false,
            dialog: { width: 400, modal: true },
            closeOnEditorCallback: true,
            getFileCallback: function(url) {
                $('#fileurl').val(url);
                // CLOSE ELFINDER HERE
                $('#elfinder').remove();  //remove Elfinder
                location.reload();   //reload Page for second selection
            }
        }).elfinder('instance');
    });
    

    })