1

The title says it all really, the way it works at the moment it will open as a popup in a new window, the problem I've found with this is that if you already have the window open and click the button to open up the popup, nothing will happen.

This means that people could potentially have the window open without realising, and get frustrated at clicking the button and having nothing happen.

Hope that makes sense, but the only way I can think to counter this would be to open KCFinder in a lightbox on the page, any ideas if this is possible?

Mark
  • 1,852
  • 3
  • 18
  • 31

1 Answers1

1

I don't think there's a way to open it in a light box but you can record the name of the window it opens then check to see if the window is open and focus on it if it is already open. Try this:

window.KCFinder = {
    callBack: function(fileUrl) {
        // do something with fileUrl
        window.KCFinder = null;
    }
};

if(typeof kcwindow == 'undefined' || kcwindow.closed) {
    kcwindow = window.open('/eshop/kcfinder/browse.php?type=images', 'kcfinder_textbox', 
        'status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1, scrollbars=0, width=800, height=500'
    );
} else {
    kcwindow.focus();
}
Styphon
  • 10,304
  • 9
  • 52
  • 86
  • It has been widely reported that window.focus() won't bring the window to the front in Chrome. – Nick Rice Apr 09 '16 at 08:00
  • @NickRice that must be new as when I wrote this answer it worked fine in Chrome. I use Chrome for development before then checking other browsers. – Styphon Apr 10 '16 at 11:06
  • Yes that's entirely possible and likely as I'm sure the bits I was reading were relatively recent. I was pulling my hair out over this same issue and resorted to closing an existing open window (if there is one) before making the open call to ensure it comes to the front. It's not nice but is fine in my situation and I can get on with something else now. I should add that I'm not sure about this - I took the easy (and cheapest) way out of the problem before fully exploring it. – Nick Rice Apr 11 '16 at 12:09