简体   繁体   English

在applet声明中调用javascript函数

[英]Call javascript function in applet declaration

I created a small applet for my sister's blog that flashes colors randomly. 我为我姐姐的博客创建了一个小程序,随机闪烁颜色。 She wants to set it as her background for her webpage. 她想将其设置为她的网页背景。 I've already figured out how to find the size of a web page and all that, but how do I declare the applet's width and height to be values of my functions? 我已经想出了如何找到网页的大小以及所有这些,但是如何将applet的宽度和高度声明为我的函数值?

Here's the tester page code: 这是测试人员页面代码:

<html>
<head>
<title>Flashing colors</title>
<script type="text/javascript">
var w = window,
    d = document,
    e = d.documentElement,
    g = d.getElementsByTagName('body')[0],
    x = w.innerWidth || e.clientWidth || g.clientWidth,
    y = w.innerHeight|| e.clientHeight|| g.clientHeight;
function getWidth(){
    return x;
}
function getHeight(){
    return y;
}
</script>
</head>

<body>

//Here's the problem

<applet code="FlashingColors.class" width=getWidth() height=getHeight()>
</applet>

</body>
</html>

I have no experience in html or javascript, but plenty in Java. 我没有html或javascript的经验,但是Java很多。 If someone could explain what to do and why it works, that would be nice. 如果有人能够解释该做什么以及它为什么会起作用,那就太好了。

Update: At this point, I do realize that one wouldn't use an applet, but at this point I just want to figure out how to make it work, because I am curious and want to learn. 更新:此时,我确实意识到不会使用applet,但此时我只想弄清楚如何使它工作,因为我很好奇并想学习。

You can't reliably layer HTML content on top of Java applets in a web page. 您无法在网页中的Java小程序之上可靠地分层HTML内容。 So this won't work anyway. 所以这无论如何都行不通。

Learn a little bit more Javascript and use that to implement the same effect. 学习更多Javascript并使用它来实现相同的效果。 It will work much better. 它会更好地工作。 (To get you started: You can assign an HTML color value directly to the document.body.style.backgroundColor property.) (为了帮助您入门:您可以将HTML颜色值直接分配给document.body.style.backgroundColor属性。)

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

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