ZeroClipboard - Uncaught Error: Error: An invalid exception was thrown

2.3k views Asked by At

I want to create Copy to clipboard button for my my Web portal that is used inside Intranet (only users that are inside company domain can access it)

To do that I used ZeroClipboard plugin. Problem is that I got this error and I don't know how to fix it:

Uncaught Error: Error: An invalid exception was thrown.

Does someone knows where's the problem?

This is code that I am using:

<button id="text-to-copy" data-clipboard-text="Click To Copy!">Click To Copy</button>

<script src= "https://cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.2.0/ZeroClipboard.Core.min.js"></script>
        <script src= "https://cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.2.0/ZeroClipboard.min.js"></script>    
<script type="text/javascript">

        var clientText = new ZeroClipboard( $("#text-to-copy"), {
            moviePath: "http://www.paulund.co.uk/playground/demo/zeroclipboard-demo/zeroclipboard/ZeroClipboard.swf",
            debug: false
        } );

        clientText.on( "load", function(clientText)
        {
            $('#flash-loaded').fadeIn();

            clientText.on( "complete", function(clientText, args) {
                clientText.setText( args.text );
                $('#text-to-copy-text').fadeIn();
            } );
        } );

            </script>
1

There are 1 answers

1
sktguha On

This is basically due to cross-protocol limitations See https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md#cross-protocol-limitations

The simplest solution is to change the src of the scripts to relative protocol , i.e Change line 2 to

<script src= "//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.2.0/ZeroClipboard.Core.min.js"></script>

and similiarly line 3 to

<script src= "//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.2.0/ZeroClipboard.min.js"></script>