IE not retreving Flash Object src from Ajax respon

2019-08-23 06:37发布

I am trying to read the src attribute of the flash file which i get in the response of a url and create a new file through swfobject. But it returns me "undefined" when i read the src of the embed tag. My code below.

The page i am doing a post on, only has the flash file in it.

The reponse is as below:

AJAX REsponse

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"     codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="930" height="630" title="Campaign">
  <param name="movie" value="final5.swf" />
  <param name="quality" value="high" />
  <embed src="final5.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="930" height="630"></embed>
</object>

Script

$.ajax({
 url: flashUrl,
 type: "POST",
 dataType:"html",
 success: function(data, status, xhr) {
   var swfUrl = flashUrl.substr(0, flashUrl.lastIndexOf('/')) + "/" + $(data).find('embed').attr('src'); 
   $('.content').html('<div id="mySwf"></div>');
   swfobject.embedSWF(swfUrl, "mySwf", "200", "200", '9.0.0', "/resources/expressInstall.swf", flashvars, attributes, params);

  }
});

***Update (found the issue area but not the solution)

I kinda got to know what the issue is, but i don't know y its occurring. when i run the page with the flash file in IE. it renderes it in a wierd way

<object width="930" height="630" title="Campaign" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" altHtml="     

 <embed src="skf-final5.swf" type="application/x-shockwave-flash" width="930" height="630" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" >    </embed>
     ">

it add some altHTML attribute to the Object and the entire embed tag goes into it which screws up the entire stuff. :(

1条回答
何必那么认真
2楼-- · 2019-08-23 07:23

Well dint find the reason y we get a "altHTML" in the tag. but found a work around for this problem.


Heres my solution. (please suggest if there can be any improvements)

$.ajax({
url: flashUrl,
type: "POST",
dataType:"html",
success: function(data, status, xhr) {
    $('.layer-view .content').html('<div id="kcSwf"></div>');
                        // Building path for flash url
    var swfUrl = flashUrl.substr(0, flashUrl.lastIndexOf('/')) + "/" + $(data).findAndSelf('param[name="movie"]').attr('value'); 
    var swfWidth = $(data).findAndSelf('object').attr('width'); 
    var swfHeight = $(data).findAndSelf('object').attr('height'); 
    var swfBgColor = $(data).findAndSelf('param[name="bgcolor"]').attr('value');

    if(swfBgColor=="undefined") swfBgColor="#ffffff";

        var layerviewWidth = parseInt(swfWidth) + 20; 
        $('.layer-view .view').css('width', layerviewWidth);

        var flashvars = false;
        var params = {salign:'t', bgcolor:swfBgColor};
        var attributes = {};
        swfobject.embedSWF(swfUrl, "kcSwf", swfWidth, swfHeight, flashVersion, "/resources/expressInstall.swf", flashvars, params, attributes);
    }
});

Note: FYI....The sequence of the properties in swfobject is also important. The Param has to come before the attribute or else it screws up some stuff in IE. :)

查看更多
登录 后发表回答