Javascript代码适用于Chrome并崩溃Firefox

时间:2013-07-28 15:07:25

标签: javascript html firefox

我的页面上有一个JavaScript代码,可以在单击图像时加载Java Applet。

它在Chrome上运行良好。当我在Firefox上加载相同的页面时,它会崩溃浏览器。

以下是摘录:

的Javascript

<script type="text/javascript">
    var appletTag;

    hideApplet(); // replace applet with clickable image
    var pic2 = new Image(703,421); // preload mouse over image 
    pic2.src = "pic2.png";

    function hideApplet() {
        var appletbox = document.getElementById('appletbox');
        appletTag = appletbox.innerHTML;

        if (navigator.appName == 'Microsoft Internet Explorer') {
            var params = "";
            var p = appletbox.getElementsByTagName("PARAM");
            for (var i = 0; i < p.length; i++) {
                params += p[i].outerHTML;
            }
            appletTag = appletTag.replace("</APPLET>", params+"</APPLET>");
        }

        appletbox.innerHTML = '<img src="gray.png" name="pic1"
                                width="703" height="421"
                                style="cursor:pointer;background-color:gray;"
                                onMouseOver="mouseOverImage()"
                                onMouseOut="mouseOutsideImage()"
                                onclick="showApplet()">';
    }

    function showApplet() {
        var appletbox = document.getElementById('appletbox');
        appletbox.innerHTML = appletTag;
    }

    function mouseOverImage() {
        document.images.pic1.src = pic2.src;
    }

    function mouseOutsideImage() {
        document.images.pic1.src = "pic1.png";
    }
</script>

调用此代码的divbox:

<div id="appletbox" style="width:703px;height:421px;">
    <applet code="TestApplet.class" codebase="."
       width="703" height="421">
    </applet>

有人可以帮我一把吗?提前谢谢。

0 个答案:

没有答案