想做一个弹出页面并且给该页面动态加载一个Flash(弹出页面的地址是空白页)
现在Chrome是可以的,但是IE下不行。代码如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="C:/Users/SylarSun/Desktop/sssss/jquery.js"></script>
<title>123123123</title>
</head><body>
<script type="text/javascript">
var swf=document.createElement("embed");
swf.setAttribute("width","160");
swf.setAttribute("height","109");
swf.setAttribute("align","middle");
swf.setAttribute("type","application/x-shockwave-flash");
swf.setAttribute("allowscriptaccess","always");
swf.setAttribute("quality","high");
swf.setAttribute("src","https://mssl.chinauma.net:446/media/uploads/14/2012-09-28/13488354947719.swf");
swf.setAttribute("wmode","transparent");
// document.appendChild(swf);

var a = document.createElement("A");
var linkStyle = "position:absolute;top:0;left:0;bottom:0;right:0;display:block;width:100%;height:expression(this.parentNode.scrollHeight);filter:alpha(opacity=0);opacity:0;background:#FFF;";
a.style.cssText = linkStyle;
a.target = "_target";
a.href = "http://www.baidu.com"; var div = document.createElement("DIV");
style="font-size:0;position:relative;width:"+160+"px;height:"+109+"px;";
div.style.cssText = style;
div.appendChild(a);
div.appendChild(swf);
window.open("about:blank").document.body.appendChild(div);
</script></body>
</html>请高手指教下!

解决方案 »

  1.   

    如果不弹出窗口,在本页面加载一个Flash元素是可以的。
    当window.open之后,就不受我的控制了。
      

  2.   

    分开写 
    <body id="bodyelement">
    <script type="text/javascript">
    var swf=document.createElement("embed");
    swf.setAttribute("width","160");
    swf.setAttribute("height","109");
    swf.setAttribute("align","middle");
    swf.setAttribute("type","application/x-shockwave-flash");
    swf.setAttribute("allowscriptaccess","always");
    swf.setAttribute("quality","high");
    swf.setAttribute("src","https://mssl.chinauma.net:446/media/uploads/14/2012-09-28/13488354947719.swf");
    swf.setAttribute("wmode","transparent");var insertid =document.getElementById("bodyelement");
    insertid.appendChild(swf);
    </script>
      

  3.   

    <script type="text/javascript">
    function init1()
    {
    var swf1=document.createElement("embed");
    swf1.setAttribute("width","260");
    swf1.setAttribute("height","109");
    swf1.setAttribute("align","middle");
    swf1.setAttribute("type","application/x-shockwave-flash");
    swf1.setAttribute("allowscriptaccess","always");
    swf1.setAttribute("quality","high");
    swf1.setAttribute("src","https://mssl.chinauma.net:446/media/uploads/14/2012-09-28/13488354947719.swf");
    swf1.setAttribute("wmode","transparent");var a = document.createElement("A");
    var linkStyle = "position:absolute;top:0;left:0;bottom:0;right:0;display:block;width:100%;height:expression(this.parentNode.scrollHeight);filter:alpha(opacity=0);opacity:0;background:#FFF;";
    a.style.cssText = linkStyle;
    a.target = "_target";
    a.href = "http://www.baidu.com";var div = document.createElement("DIV");
    style="font-size:0;position:relative;width:"+160+"px;height:"+109+"px;";
    div.style.cssText = style;
    div.appendChild(a);
    //div.appendChild(swf1);
    window.open("about:blank").document.body.appendChild(div);//documnet.appendChild(swf);
    }
    window.onload=init1;
    </script>
      

  4.   

    把 那个开打新页面的代码 最后,通过window.onload  加载
      

  5.   


    新打开的页面不是一个物理文件,不在我的服务器上
    我是动态的去生成,就是window.open('about:blank'...)这种方式
      

  6.   

    因为IE生成的about:blank没有body元素和chrome不一样 你看下页面的源码就知道了 只有单独的一个html元素 你这样肯定搞不定了
      

  7.   


    是有body的,也添加成功了一些元素.
    可是现在遇到了一个问题,就是我想插入一个Flash,他不显示
    我猜想是他没有加载FlashPlayer插件  这个怎么弄呢
      

  8.   

    - -哪有body 
    flash插件不加载是ie设置里的问题吧
      

  9.   

    现在的问题是我window.open之后,div以及我的A标签都可以显示
    但是不加载FlashPlayer. 哎 郁闷
      

  10.   

    改document.write试试,我这里IE7,8没问题<!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="C:/Users/SylarSun/Desktop/sssss/jquery.js"></script>
    <title>123123123</title>
    </head><body>
    <script type="text/javascript">
        var swf = document.createElement("embed");
        swf.setAttribute("width", "160");
        swf.setAttribute("height", "109");
        swf.setAttribute("align", "middle");
        swf.setAttribute("type", "application/x-shockwave-flash");
        swf.setAttribute("allowscriptaccess", "always");
        swf.setAttribute("quality", "high");
        swf.setAttribute("src", "https://mssl.chinauma.net:446/media/uploads/14/2012-09-28/13488354947719.swf");
        swf.setAttribute("wmode", "transparent");
        // document.appendChild(swf);    var a = document.createElement("A");
        var linkStyle = "position:absolute;top:0;left:0;bottom:0;right:0;display:block;width:100%;height:expression(this.parentNode.scrollHeight);filter:alpha(opacity=0);opacity:0;background:#FFF;";
        a.style.cssText = linkStyle;
        a.target = "_target";
        a.href = "http://www.baidu.com";    var div = document.createElement("DIV");
        style = "font-size:0;position:relative;width:" + 160 + "px;height:" + 109 + "px;";
        div.style.cssText = style;
        div.appendChild(a);
        div.appendChild(swf);    var fragment = document.createElement('fragment');
        fragment.appendChild(div);    var win = window.open("about:blank")//.document.body.appendChild(div);
        win.document.open();
        win.document.write(fragment.innerHTML);
        win.document.close();
    </script></body>
    </html>
      

  11.   

    Quote: 引用 13 楼 showbo 的回复:

    改document.write试试,我这里IE7,8没问题感谢版主!!! 
    完美解决了我的问题.
      

  12.   

    showbo:
    顺便问一下怎么给一个iframe  write一个元素呢?
    ie8和9都不一样 
      

  13.   

    一样啊,你获取不对吧<iframe id="ifr" width="400" height="200" src="about:blank"></iframe>
    <script type="text/javascript">    window.onload = function () {
            var doc = document.getElementById('ifr').contentWindow.document;
            doc.open();
            doc.write(new Date());
            doc.close();
        }
    </script>
      

  14.   

    确实好用.  是我的写法有问题.
    请问这个doc.open是什么思路呢? 太厉害了...