5

Originally, this post was regarding my attempts to inject ZeroClipboard into web pages by and for use by my Chrome extension, but I've dumbed the scenario down and down and down in a seemingly futile attempt to identify the issue and I still can't get it to work.

I'm even having difficulty getting the actual, documented "Minimal Example" on ZeroClipboard's own GitHub to work (admittedly, I've modded the source to actually be HTML5-valid, but the exact original didn't work either). Even test.html, which is included in the tar.gz archive, doesn't work!

"Minimal Example": Code

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
    </head>
    <body>
        <input type="button" id="d_clip_button" data-clipboard-text="Copy Me!" value="Copy To Clipboard" />
        <script src="ZeroClipboard.js"></script>
        <script>
            var clip = new ZeroClipboard( document.getElementById('d_clip_button') );
        </script>
    </body>
</html>

"Minimal Example": Console Output

Uncaught TypeError: object is not a function  index.html:11

Info

  • The entire contents of the zeroclipboard-1.0.7.tar.gz archive are in the same directory as index.html.
  • The ZeroClipboard.js file isn't corrupted / incomplete and is being loaded correctly.
  • I'm using Chrome v24.0.1312.52

 

Either I'm missing something really, really obvious here or ZeroClipboard's documentation / functionality is abysmal.

mythofechelon
  • 3,692
  • 11
  • 37
  • 48

5 Answers5

2

What I've just found out:

That didn't match. I've got a similar error than the original poster of this question.

After I used the example from GitHub I've succeeded.

Conclusion:

Either use both the example and download from Google Code or (which I would prefer), both the example and download from GitHub.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
1

you will need to specify the path to the swf file :

 var clip = new ZeroClipboard( document.getElementById('d_clip_button'),{moviePath: "/path/ZeroClipboard.swf"} );
mLar
  • 2,967
  • 2
  • 22
  • 23
0

For me, the problem was that the variable module was already defined by the framework I use and not meant to be use like ZeroClipboard do. In fact, if you look at the end of the ZeroClipboard.js file, here is what you can see:

  if (typeof module !== "undefined") {
    module.exports = ZeroClipboard;
  } else if (typeof define === "function" && define.amd) {
    define(function() {
      return ZeroClipboard;
    });
  } else {
    window.ZeroClipboard = ZeroClipboard;
  }

I just replaced this by the following code to fix the issue:

window.ZeroClipboard = ZeroClipboard;
Nicolas BADIA
  • 5,612
  • 7
  • 43
  • 46
0

Try the 2.2.1-dev version: http://datatables.net/download/build/dataTables.tableTools.nightly.js?_=60133663e907c73303e914416ea258d8 I think it should be resolve there. I would also point out that new $.fn.dataTable.TableTools(...) is now the preferred form. The TableTools global is still in 2.2.x, but will be removed in 2.3+.

user3559718
  • 81
  • 1
  • 4
-1

For loading an external script, inserting a SCRIPT element into the page body will not immediately load and execute the script. The appendChild will return immediately, and the script will be loaded after the current script execution returns from all functions and goes into idle state.

For this, the SCRIPT element's onload property can be used to execute a code once the external script is loaded.

function inject_zeroClipboard(){
    var path_Root_zeroClipboard = chrome.extension.getURL("plugins/zeroClipboard");
    var element_Head = document.getElementsByTagName('head')[0];
    var element_zeroClipboard = document.createElement("script");
    element_zeroClipboard.src = path_Root_zeroClipboard + "/ZeroClipboard.js";

    element_zeroClipboard.onload = function() {
        ZeroClipboard.setMoviePath(path_Root_zeroClipboard + "/ZeroClipboard10.swf");
        var clip = new ZeroClipboard.Client();
        clip.glue("element_Example");
        clip.addEventListener("click", function(){
            clip.setText(data_Example);
        });
    };

    element_Head.appendChild(element_zeroClipboard);
}
Jay
  • 4,627
  • 1
  • 21
  • 30
  • Make sure the `ZeroClipboard.js` file is not corrupted or partially loaded, which prevent the `ZeroClipboard` object from being created. Check the error before the `Uncaught ReferenceError: ZeroClipboard is not defined`. – Jay Oct 27 '12 at 15:55
  • Nope. `ZeroClipboard.js` is fully loaded. – mythofechelon Jan 23 '13 at 16:52
  • – rabbit.aaron Jan 12 '16 at 04:06