我正在尝试在页面的onload上动态创建此html元素;但是,当我运行它时,该代码无法在IE8上正常运行,但在Firefox,Safari和其他浏览器中还可以。


 function getmovie() {
           var container = document.getElementById("container");
           if (!container)
               return;
           var object = document.createElement("object");
           object.setAttribute("width", "512");
           object.setAttribute("height", "296");
           var param1 = document.createElement("param");
           param1.setAttribute("name", "movie");
           param1.setAttribute("value", "url");
           var param2 = document.createElement("param");
           param2.setAttribute("name", "allowFullScreen");
           param2.setAttribute("value", "true");
           var embed = document.createElement("embed");
           embed.setAttribute("src", "my url");
           embed.setAttribute("type", "application/x-shockwave-flash");
           embed.setAttribute("allowFullScreen", "true");
           embed.setAttribute("width", "512");
           embed.setAttribute("height", "296");
           object.appendChild(param1);
           object.appendChild(param2);
           object.appendChild(embed);
           container.appendChild(object);
           }

谁能纠正我的代码?

最佳答案

除非您有充分的理由手动构建包含DOM元素的Flash,否则请考虑通过对类似SWFObject之类的框架的单个调用来替换代码,该框架可以为您完成所有“肮脏的工作”。

swfobject.embedSWF("flashmovie.swf", "container", "512", "296", "9.0.0",
    "expressInstall.swf", { allowFullScreen : true });

关于javascript - Javascript在IE8中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1788639/

10-12 01:02