简体   繁体   English

Safari及更高版本的Java Applet z-index

[英]Java Applet z-index on Safari and beyond

A well known problem with Java Applets in webpages is that browsers ignore the z-index of the applet tag vs. other components in the page. 网页中Java Applet的一个众所周知的问题是浏览器会忽略applet标记的z-index与页面中的其他组件。 No matter how you position and z-index elements in the page, applets will draw themselves on top of everything. 无论你如何在页面中定位和z-index元素,applet都会在所有内容之上绘制自己。

There is a workaround, known as the iframe shim, as described here: http://www.oratransplant.nl/2007/10/26/using-iframe-shim-to-partly-cover-a-java-applet/ . 有一种解决方法,称为iframe垫片,如下所述: http//www.oratransplant.nl/2007/10/26/using-iframe-shim-to-partly-cover-a-java-applet/

However, this workaround does not work in Safari 3 or 4 in Windows (assuming the same for Mac). 但是,此解决方法在Windows中的Safari 3或4中不起作用(对于Mac,假设相同)。

Does anyone know a way to make it work in Safari? 有没有人知道在Safari中使用它的方法?

Does anyone have ideas about how to pressure Sun to fix the underlying problem so we can avoid clumsy shims? 有没有人有关于如何迫使Sun解决潜在问题的想法,以便我们可以避免笨拙的垫片? Here is a bug report on the issue, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6646289 , notice that it has been open for a year, however other bug reports go back many many years. 这是关于该问题的错误报告, http://bugs.sun.com/bugdatabase/view_bug.do?bad_id = 6646289 ,注意它已经开放了一年,但是其他错误报告可以追溯到很多年。

This is so frustrating, don't Sun understand that this is the very sort of thing that has marginalized Java as a way of doing cool stuff in the browser? 这太令人沮丧了,难道Sun不明白这是将Java作为在浏览器中做一些很酷的事情的边缘化的事情吗? I love you Java, but you are not helping your situation... 我爱你Java,但你没有帮助你的情况......

There is a tricky solution for the problem. 这个问题有一个棘手的解决方案。 It's not necessary to have the code inside an iframe . 没有必要在iframe包含代码。 We can have a dummy iframe just as a layer above the applet. 我们可以将虚拟iframe作为applet上方的一层。 And then an absolute div with the text can easily placed above that iframe . 然后,带有文本的绝对div可以轻松放在iframe上方。

working example 工作实例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Applet z index issue</title>
<style>

.applet {width:400px; margin:0 auto; text-align:center; border:1px solid #000; left:40%; position:absolute }
.iframe {width:400px;  background:#fff; position:absolute; border:1px solid #f00; position:absolute; left:45%; top:20px; z-index:9; height:201px;}
.message { width:250px; border:1px solid #000; background:#fff; height:150px; color:#fff; text-align:center;  z-index:99; background:#555;  float:left; position:absolute; left:45%; top:20px}

 </style>
</head>

<body>
<div class="message">Message</div>
<div class="iframe"><iframe style="width:500px; height:205px; background:none; border:none"> </iframe></div>
<div class="applet">

<applet code="Bubbles.class" width="400" height="350">
Java applet that draws animated bubbles.
</applet>

</div>

</body>
</html>

Actually problem is not related to z-index at all. 实际上问题根本与z-index无关。 It's caused by "windowed" drawing model of Netscape Plugin API (NPAPI). 它是由Netscape Plugin API(NPAPI)的“窗口”绘图模型引起的。

You can't do anything about it (except the shim). 你不能做任何事情(垫片除外)。 Plugin author has to rewrite it using windowless API . 插件作者必须使用无窗口API重写它

For one, Java on Mac is actually built by Apple and not Sun. 首先,Mac上的Java实际上是由Apple而不是Sun构建的。 As for the applets, we hide the applets when there is something appearing on top of it. 对于applet,我们隐藏applet,当它们出现在它上面时。 That might not suffice for your needs though. 但这可能不足以满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM