IE 中的 jQuery UI 对话框和 Flash
我一直在尝试获取零剪贴板和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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,powtac 确实为我指明了正确的方向,但缺少一个元素:使用 jQuery
html()
函数与简单设置innerHTML
没有相同的效果。如果有人能解释原因就好了。因此,固定代码如下所示:
另外,我忘记将 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 settinginnerHTML
. If would be nice if somebody could explain why.So, the fixed code looks like this:
Also, I forgot to put DOCTYPE in the example page, so the offsets are wrong in IE. My bad.
我将您的答案改编为可重用的方法,并修复了一些位置问题(我必须添加position:absolute,并使用
outerWidth()
和outerHeight()
。演示。
I adapted your answer to a reusable method, and fixed a few position issues (I had to add position:absolute, and use
outerWidth()
andouterHeight()
.Demo.