IE 中的 jQuery UI 对话框和 Flash

发布于 2024-08-07 06:58:54 字数 1827 浏览 8 评论 0原文

我一直在尝试获取零剪贴板jQuery UI Dialog 一起玩得很好,事实证明这是相当困难的。

零剪贴板允许通过将透明 Flash 影片放置在按钮上来从 Javascript 复制到剪贴板,以便用户在尝试单击按钮时单击 Flash。正如您在演示页面中看到的那样,它运行良好且跨浏览器。

然而,当尝试在 jQuery UI 对话框中使用它时,似乎出现了问题。

首先,我发现flash元素必须放在dialog元素内部,否则Chrome和IE拒绝响应点击事件。这意味着我无法使用 glue 便捷方法,但没关系。

但是,现在 IE 由于某种原因不接受 Flash 元素上的 setText 方法。

我所做的一个例子是这里。我的代码从第 300 行左右开始,最相关的行是:

$("#showme").dialog({autoOpen: false, width: 550, height: 200});
$("#showme").bind("dialogopen", function() {
    if($("#clipflash").length == 0) {
        var btn = $("#d_clip_button");
        $("<div id='clipflash' style='position:absolute; background: #f00; z-index: 9999' />")
            .css(btn.position())
            .width(btn.width())
            .height(btn.height())
            .html(clip.getHTML(btn.width(), btn.height()))
            .appendTo("#showme");
    }
});

为了安全起见,我将 div 着色为红色,以便更容易发现并将其 z 索引设置为 9999。然后,我设置位置和大小以覆盖“按钮”,并使用 clip.getHTML() 添加 Flash 元素的 HTML。

我已经为此工作了几个小时,因此我们将不胜感激。

差点忘了:我的问题是 IE7 在零剪贴板代码中显示“对象不支持此属性或方法”。

更新

powtac 的评论指出了一些看起来非常有希望的事情:

我忘记了自己的黄金法则: Flash 外部接口的顺序 要在 IE 7 中工作,您必须填充 将 HTML 嵌入/对象 HTML 到 DIV 元素中 之后它被附加到 DOM 中。愚蠢的IE。

但是,切换行 .html(clip.getHTML(btn.width(), btn.height())).appendTo("#showme") 并没有'没有帮助。即使稍后使用 setTimeout 添加 Flash HTML 也没有帮助。我觉得我真的很接近,但......

I've been trying to get Zero Clipboard and jQuery UI Dialog to play nice together, and it's proving to be rather difficult.

Zero Clipboard allows copying to clipboard from Javascript by placing a transparent Flash movie over a button, so that the user clicks on the Flash when he tried to click the button. This works nicely and cross-browser as you can see in the demo page.

However, when trying to use this in a jQuery UI Dialog box something seems to go wrong.

First, I discovered that the flash element must be placed inside the dialog element, otherwise Chrome and IE refuse to respond to click events. This means I can't use the glue convenience method, but that's OK.

However, now IE for some reason won't accept the setText method on the Flash element.

An example of what I did is here. My code starts around line 300, and the most relevant lines are:

$("#showme").dialog({autoOpen: false, width: 550, height: 200});
$("#showme").bind("dialogopen", function() {
    if($("#clipflash").length == 0) {
        var btn = $("#d_clip_button");
        $("<div id='clipflash' style='position:absolute; background: #f00; z-index: 9999' />")
            .css(btn.position())
            .width(btn.width())
            .height(btn.height())
            .html(clip.getHTML(btn.width(), btn.height()))
            .appendTo("#showme");
    }
});

I colored the div red so it's easier to spot and set its z-index to 9999, just to be safe. I then set the position and size to cover the "button", and add the HTML for the Flash element with clip.getHTML().

I've been working on this for several hours now, so any help would be greatly appreciated.

Almost forgot: my problem is that IE7 says "Object does not support this property or method" inside the Zero Clipboard code.

UPDATE

powtac's comment points to something that looks really promising:

I forgot the own golden rule: In
order for the Flash ExternalInterface
to work in IE 7, you have to stuff the
EMBED/OBJECT HTML into the DIV element
AFTER it gets appended to the DOM. Stupid IE.

However, switching the lines .html(clip.getHTML(btn.width(), btn.height())) and .appendTo("#showme") didn't help. Even doing a setTimeout for adding the flash HTML later did not help. I feel like I'm really close, though...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似梦非梦 2024-08-14 06:58:55

好的,powtac 确实为我指明了正确的方向,但缺少一个元素:使用 jQuery html() 函数与简单设置 innerHTML 没有相同的效果。如果有人能解释原因就好了。

因此,固定代码如下所示:

$("#showme").bind("dialogopen", function() {
    if($("#clipflash").length == 0) {
        var btn = $("#d_clip_button");
        $("<div id='clipflash' style='position:absolute; background: #f00; z-index: 9999' />")
            .css(btn.position())
            .width(btn.width())
            .height(btn.height())
            .appendTo("#showme")
            [0].innerHTML = clip.getHTML(btn.width(), btn.height());
    }
});

另外,我忘记将 DOCTYPE 放入示例页面中,因此 IE 中的偏移量是错误的。我的不好。

OK, so powtac did point me in the right direction, but there was one element missing: using the jQuery html() function did not have the same effect as simply setting innerHTML. If would be nice if somebody could explain why.

So, the fixed code looks like this:

$("#showme").bind("dialogopen", function() {
    if($("#clipflash").length == 0) {
        var btn = $("#d_clip_button");
        $("<div id='clipflash' style='position:absolute; background: #f00; z-index: 9999' />")
            .css(btn.position())
            .width(btn.width())
            .height(btn.height())
            .appendTo("#showme")
            [0].innerHTML = clip.getHTML(btn.width(), btn.height());
    }
});

Also, I forgot to put DOCTYPE in the example page, so the offsets are wrong in IE. My bad.

白首有我共你 2024-08-14 06:58:55

我将您的答案改编为可重用的方法,并修复了一些位置问题(我必须添加position:absolute,并使用outerWidth()outerHeight()

演示

function setupCopier(selector, buttonSelector, callback, opt_dialogSelector){
  var copiedText = $(selector).text();
  ZeroClipboard.setMoviePath('http://dl.dropbox.com/u/464119/Programming/javascript/libraries/ZeroClipboard/ZeroClipboard.swf');
  var clip = new ZeroClipboard.Client();
  clip.setText(copiedText);
  clip.addEventListener('complete', callback);

  $(buttonSelector).each(function(){
    clip.glue(this);
  });

  // Make sure Zero Clipboard is on top
  $("#ZeroClipboardMovie_1").
    parent().
    css("z-index", 2000);

  if (opt_dialogSelector) {
    $(opt_dialogSelector).bind("dialogopen", function() {
      if($("#clipflash").length === 0) {
        var btn = $(opt_dialogSelector).find(buttonSelector);
        $("<div id='clipflash' style='position:absolute; z-index: 9999' />")
          .css(btn.position())
          .width(btn.outerWidth())
          .height(btn.outerHeight())
          .appendTo(opt_dialogSelector)
          [0].innerHTML = clip.getHTML(btn.outerWidth(), btn.outerHeight());
      }
    });
  }
}

$(function(){
  setupCopier('#copy-div', '.copy-button', function(){
    alert("Copied");
  }, '#dialog');

  $("#open-dialog-button").click(function(){
    $("#dialog").dialog("open");
  });

  $("#dialog").dialog({autoOpen: false, modal: true, resizable: false, draggable: false,
        title: "Create your Free Personal Bar now", height:200, width:300});
});

I adapted your answer to a reusable method, and fixed a few position issues (I had to add position:absolute, and use outerWidth() and outerHeight().

Demo.

function setupCopier(selector, buttonSelector, callback, opt_dialogSelector){
  var copiedText = $(selector).text();
  ZeroClipboard.setMoviePath('http://dl.dropbox.com/u/464119/Programming/javascript/libraries/ZeroClipboard/ZeroClipboard.swf');
  var clip = new ZeroClipboard.Client();
  clip.setText(copiedText);
  clip.addEventListener('complete', callback);

  $(buttonSelector).each(function(){
    clip.glue(this);
  });

  // Make sure Zero Clipboard is on top
  $("#ZeroClipboardMovie_1").
    parent().
    css("z-index", 2000);

  if (opt_dialogSelector) {
    $(opt_dialogSelector).bind("dialogopen", function() {
      if($("#clipflash").length === 0) {
        var btn = $(opt_dialogSelector).find(buttonSelector);
        $("<div id='clipflash' style='position:absolute; z-index: 9999' />")
          .css(btn.position())
          .width(btn.outerWidth())
          .height(btn.outerHeight())
          .appendTo(opt_dialogSelector)
          [0].innerHTML = clip.getHTML(btn.outerWidth(), btn.outerHeight());
      }
    });
  }
}

$(function(){
  setupCopier('#copy-div', '.copy-button', function(){
    alert("Copied");
  }, '#dialog');

  $("#open-dialog-button").click(function(){
    $("#dialog").dialog("open");
  });

  $("#dialog").dialog({autoOpen: false, modal: true, resizable: false, draggable: false,
        title: "Create your Free Personal Bar now", height:200, width:300});
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文