1

I have a problem with the Cute File Browser and this script

On the Stackoverflow Page the copy to clipboard works but when I add the script into the cute file browser to copy the link on click it doesn't work and also the browser ignores the

e.preventDefault() 

code. Can you please help me and say whats wrong?

so this is from the script.js with the added code:

// Clicking on breadcrumbs
    breadcrumbs.on('click', 'a', function(e){
        e.preventDefault();

        var index = breadcrumbs.find('a').index($(this)),
            nextDir = breadcrumbsUrls[index];                            
                    breadcrumbsUrls.length = Number(index);

                    //before it was window.location.hash instead of var cope
        var cope = encodeURIComponent(nextDir);
        var aux = document.createElement("input");
        aux.setAttribute("type", "text");
        aux.setAttribute("id", "temp");
        aux.setAttribute("style", "position:absolute;opacity:0;");
        aux.setAttribute("value", cope);
        document.body.appendChild(aux);
        aux.select();
        document.execCommand("copy");
        document.body.removeChild(aux);
    });

what am I doing wrong?

Community
  • 1
  • 1
MAX
  • 23
  • 4
  • Are you trying to copy the value of a hidden text input field? – DavidDomain Aug 04 '15 at 07:31
  • @DavidDomain yes, i'm trying to put the url in the hidden input field and than i want to copy the value.... And I tried the script on stackoverflow and it worked there, so somehow it must work in that script too... – MAX Aug 04 '15 at 07:34
  • This works for me. You seem to be comparing something with `breadcrumbsUrls`, do a `consol.log` to see if it is giving you what you want. Preventing default action works as well. Take look at the [**Fiddle**](https://jsfiddle.net/7n0qw0jk/). Did not change much of your code, but since i do not know what your HTML looks like and how and where did you include the script, it is hard to tell what is going on. – DavidDomain Aug 04 '15 at 08:11
  • It's not working... I put the script in this Fiddle maybe you could have a look? :) https://jsfiddle.net/kevaxq2g/3/ and i uploaded the files here so you can test because the php doesn't work in the fiddle https://static.mximum.com – MAX Aug 04 '15 at 09:00
  • Can you at least add one folder on your site? So that there are any breadcrumbs. So i can test. Right now there are no breadcrumbs. – DavidDomain Aug 04 '15 at 09:22
  • so I added some stuff :) – MAX Aug 04 '15 at 09:28
  • Ok, so this is working on chrome, but not on Firefox. Are testing on Firefox? – DavidDomain Aug 04 '15 at 09:34
  • And I think it doesn't copy the link of the files instead it copies the link of the navigation with the arrow on click – MAX Aug 04 '15 at 09:34
  • I'm testing it on Microsoft Edge and IE. Edit: But to copy the link of the breadcrump doesn't work in Chrome too. – MAX Aug 04 '15 at 09:35
  • For IE there is a workaround. See my answer on this [**post**](http://stackoverflow.com/questions/31593297/using-execcommand-javascript-to-copy-hidden-text-to-clipboard/31596687#31596687). Of course it is coping the navigation link, because that is what you are adding to the text input value. Or at least this is what i added to it, since i dont know what is in `breadcrumbsUrls` – DavidDomain Aug 04 '15 at 09:37
  • oh.. well but that's not what I want... i want that if i click e.g. on the main page on test.txt it than copies me https://static.mximum.com/files/test.txt to the clipboard... I'm sorry :P – MAX Aug 04 '15 at 09:41

1 Answers1

-2

I had a hard time getting that to to work as well. I disected the whole thing and fiddled it. You are welcome to fork. Fiddle

breadcrumbsUrls
Pat B
  • 1