3

If I put a script tag in the HTML page, it will work, but when I load an external page with the ZeroClipboard library included in it, I can't get it to work. The object gets created, and is over the correct element, but it doesn't emit any events, and doesn't copy the clipboard text. Example:

var ZeroClipboard = defineZClip(); // This is a scoped function that has the zclip library in it

window.onload = function () {

    console.log("doc loaded"); // This fires

    var button = document.getElementById('z-button');
    var clip = new ZeroClipboard(button, {
        moviePath: 'ZeroClipboard.swf'
    });
    clip.on('load', function () {
        console.log("loaded"); // This never fires
    })

};

I can get around this by dynamically inserting a script tag with the contents of the script tag initializing ZeroClipboard, but if I initialize it from my script it doesn't work. Like so:

var ZeroClipboard = defineZClip();
window.ZeroClipboard = ZeroClipboard;

window.onZeroLoad = function (clip) {
    console.log("zero loaded"); // This fires
};

var scriptText = 'window.onload = function () { console.log("window loaded");var button = document.getElementById("z-button");'
            +' var clip = new ZeroClipboard(button, {moviePath: "ZeroClipboard.swf"});'
            +' clip.on("load", window.onZeroLoad );'
            +'};'
var script = document.createElement('script');
script.innerHTML = scriptText;
document.head.appendChild(script);

This offers some distinct disadvantages, though. Such as...it sort of defeats the purpose of having everything scoped, since now ZeroClipboard will HAVE to be accessible via the window. Plus it's much harder to read and all that.

adiktofsugar
  • 1,439
  • 14
  • 17
  • I'm seeing the same thing: The flash object is created and correctly placed on the page, but events never fire. – bibs Mar 06 '14 at 14:40

0 Answers0