在 IE 中克隆对象 (.clone) 时出现问题

发布于 2024-10-06 16:35:40 字数 5444 浏览 0 评论 0原文

我正在 ie 中克隆 Flash,并同时更改一些变量。这是这个函数:

$(function() {
  $("select[name='variation3']").live('change', function() {
    var player = $(this).parent().parent().parent().find('object:first');
    if(player.length == 0)
      player = $(this).parent().parent().parent().find('.player_not_single, .player_singele');

    var $param = player.find("param[name='flashvars']");
    var path = player.closest('.post1').attr('data-demo');

    //$param.attr('value', $param.attr('value').replace(/soundFile=([^&]+)/, 'soundFile=' + path + $(this).find(':selected').val() + '.mp3'));

    $param.attr("value", function(i,v) { return v.replace(/soundFile=([^&]+)/, 'soundFile=' + path + $(this).find(':selected').val() + '.mp3'); });

    var new_player = player.clone();
    new_player.insertBefore(player);
    player.remove();
  });
});

在 FF 中工作正常,但在 IE 中却出现问题。这是克隆之前的代码:

<object name="audioplayer_1" width="270" height="24" id="audioplayer_1"
        classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        style="outline-style:none; outline-color:invert; outline-width:medium;">  
  <param name="bgcolor" value="#FFFFFF"/>  
  <param name="wmode" value="transparent"/>  
  <param name="menu" value="false"/>  
  <param name="flashvars"  value="animation=no&encode=no&initialvolume=60&remaining=no&noinfo=yes&buffer=3&checkpolicy=no&rtl=no&bg=363635&text=333333&leftbg=4f4f4f&lefticon=787171&volslider=71bced&voltrack=777987&rightbg=4d4d4d&rightbghover=66a7d9&righticon=969696&righticonhover=000000&track=c2bebe&loader=5f91f5&border=000000&tracker=90b7d1&skip=b3b3b3&soundFile=http%3A%2F%2Fwww.gameaudio.net%2Fprelisten%2Fanotherworld%2Ffulledit.mp3&playerID=audioplayer_1"/>  
  <param name="movie" value="http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1"/>  
</object>  

这是克隆之后的代码:

<object name="audioplayer_1" width="270" height="24" id="audioplayer_1"
        classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        style="outline-style:none; outline-color:invert; outline-width:medium;">  
  <param name="_cx" value="7143"/>  
  <param name="_cy" value="635"/>  
  <param name="FlashVars" value=""/>  
  <param name="Movie" value="http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1"/>  
  <param name="WMode" value="Transparent"/>  
  <param name="BGColor" value="FFFFFF"/>  
  [...]  
</object>

不一样。部分是的,但不是全部,尤其是。最重要的部分缺失了。 可能是什么错误?

更新: 这是我当前的代码: 'function embedAudioPlayer(replaceElemIdStr, audioFile) {

swfobject.embedSWF(   
    "http://www.gameaudio.net/wp-content/plugins/audio-player/assets  /player.swf?ver=2.0.4.1",   
    replaceElemIdStr,   
    width,   
    height,   
    "9.0.115",   
    "expressInstall.swf",  
    {  
        soundFile: audioFile  
    });  

}

$(function() {

$("select[name='variation3']").live('change', function() {

player = $(this).parent().parent().parent().find('.player_not_single,   .player_singele');

var $param = player.find("param[name='flashvars']");  
var path = player.closest('.post1').attr('data-demo');  
var audioFile = path + $(this).find(':selected').val() + '.mp3';  
var uniqueId = 'audio-' + +new Date;  
player.replaceWith('<div id="+uniqueId+"/>');  
embedAudioPlayer(uniqueId, audioFile);  

}); '

函数 embedAudioPlayer(replaceElemIdStr, audioFile) { var swfobject = audioplayer_swfobject;
swfobject.embedSWF( “http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1”, 替换ElemIdStr, 250、 50、 “9.0.115”, “expressInstall.swf”, { 声音文件:音频文件 }); }

$(function() {

$("select[name='variation3']").live('change', function() {

player = $(this).parent().parent().parent().find('.player_not_single, .player_singele');

var $param = player.find("param[name='flashvars']");
var path = player.closest('.post1').attr('data-demo');
var audioFile = path + $(this).find(':selected').val() + '.mp3';
var uniqueId = 'audio-' + +new Date;
player.replaceWith('<div id="+uniqueId+"/>');
embedAudioPlayer(uniqueId, audioFile);

});

更新:

` 函数 embedAudioPlayer(replaceElemIdStr,audioFile){ var swfobject = audioplayer_swfobject;
swfobject.embedSWF( “http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1”, 替换ElemIdStr, 250、 50、 “9.0.115”, “expressInstall.swf”, { 声音文件:音频文件 }); }

$(function() {

$("select[name='variation3']").live('change', function() {

player = $(this).parent().parent().parent().find('.player_not_single, .player_singele');

var $param = player.find("param[name='flashvars']");
var path = player.closest('.post1').attr('data-demo');
var audioFile = path + $(this).find(':selected').val() + '.mp3';
var uniqueId = 'audio-' + +new Date;
player.replaceWith('<div id="+uniqueId+"/>');
embedAudioPlayer(uniqueId, audioFile);

});`

I am cloning a flash in ie and change some variable while that. This is the function:

$(function() {
  $("select[name='variation3']").live('change', function() {
    var player = $(this).parent().parent().parent().find('object:first');
    if(player.length == 0)
      player = $(this).parent().parent().parent().find('.player_not_single, .player_singele');

    var $param = player.find("param[name='flashvars']");
    var path = player.closest('.post1').attr('data-demo');

    //$param.attr('value', $param.attr('value').replace(/soundFile=([^&]+)/, 'soundFile=' + path + $(this).find(':selected').val() + '.mp3'));

    $param.attr("value", function(i,v) { return v.replace(/soundFile=([^&]+)/, 'soundFile=' + path + $(this).find(':selected').val() + '.mp3'); });

    var new_player = player.clone();
    new_player.insertBefore(player);
    player.remove();
  });
});

In FF it works fine, but inIE it makes problems. This is the code before the cloning:

<object name="audioplayer_1" width="270" height="24" id="audioplayer_1"
        classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        style="outline-style:none; outline-color:invert; outline-width:medium;">  
  <param name="bgcolor" value="#FFFFFF"/>  
  <param name="wmode" value="transparent"/>  
  <param name="menu" value="false"/>  
  <param name="flashvars"  value="animation=no&encode=no&initialvolume=60&remaining=no&noinfo=yes&buffer=3&checkpolicy=no&rtl=no&bg=363635&text=333333&leftbg=4f4f4f&lefticon=787171&volslider=71bced&voltrack=777987&rightbg=4d4d4d&rightbghover=66a7d9&righticon=969696&righticonhover=000000&track=c2bebe&loader=5f91f5&border=000000&tracker=90b7d1&skip=b3b3b3&soundFile=http%3A%2F%2Fwww.gameaudio.net%2Fprelisten%2Fanotherworld%2Ffulledit.mp3&playerID=audioplayer_1"/>  
  <param name="movie" value="http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1"/>  
</object>  

And this the code after cloning:

<object name="audioplayer_1" width="270" height="24" id="audioplayer_1"
        classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        style="outline-style:none; outline-color:invert; outline-width:medium;">  
  <param name="_cx" value="7143"/>  
  <param name="_cy" value="635"/>  
  <param name="FlashVars" value=""/>  
  <param name="Movie" value="http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1"/>  
  <param name="WMode" value="Transparent"/>  
  <param name="BGColor" value="FFFFFF"/>  
  [...]  
</object>

It is not the same. In parts yes, but not all and esp. the most important parts are missing.
What could be the error?

UPDATE:
This is my current code:
'function embedAudioPlayer(replaceElemIdStr, audioFile) {

swfobject.embedSWF(   
    "http://www.gameaudio.net/wp-content/plugins/audio-player/assets  /player.swf?ver=2.0.4.1",   
    replaceElemIdStr,   
    width,   
    height,   
    "9.0.115",   
    "expressInstall.swf",  
    {  
        soundFile: audioFile  
    });  

}

$(function() {

$("select[name='variation3']").live('change', function() {

player = $(this).parent().parent().parent().find('.player_not_single,   .player_singele');

var $param = player.find("param[name='flashvars']");  
var path = player.closest('.post1').attr('data-demo');  
var audioFile = path + $(this).find(':selected').val() + '.mp3';  
var uniqueId = 'audio-' + +new Date;  
player.replaceWith('<div id="+uniqueId+"/>');  
embedAudioPlayer(uniqueId, audioFile);  

});
'

function embedAudioPlayer(replaceElemIdStr, audioFile) {
var swfobject = audioplayer_swfobject;
swfobject.embedSWF(
"http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1",
replaceElemIdStr,
250,
50,
"9.0.115",
"expressInstall.swf",
{
soundFile: audioFile
});
}

$(function() {

$("select[name='variation3']").live('change', function() {

player = $(this).parent().parent().parent().find('.player_not_single, .player_singele');

var $param = player.find("param[name='flashvars']");
var path = player.closest('.post1').attr('data-demo');
var audioFile = path + $(this).find(':selected').val() + '.mp3';
var uniqueId = 'audio-' + +new Date;
player.replaceWith('<div id="+uniqueId+"/>');
embedAudioPlayer(uniqueId, audioFile);

});

Update:

`
function embedAudioPlayer(replaceElemIdStr, audioFile) {
var swfobject = audioplayer_swfobject;
swfobject.embedSWF(
"http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1",
replaceElemIdStr,
250,
50,
"9.0.115",
"expressInstall.swf",
{
soundFile: audioFile
});
}

$(function() {

$("select[name='variation3']").live('change', function() {

player = $(this).parent().parent().parent().find('.player_not_single, .player_singele');

var $param = player.find("param[name='flashvars']");
var path = player.closest('.post1').attr('data-demo');
var audioFile = path + $(this).find(':selected').val() + '.mp3';
var uniqueId = 'audio-' + +new Date;
player.replaceWith('<div id="+uniqueId+"/>');
embedAudioPlayer(uniqueId, audioFile);

});`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遥远的绿洲 2024-10-13 16:35:40

Firefox 和除 IE 之外的所有浏览器均使用 用于 Flash 的 Netscape 插件应用程序编程接口 (NPAPI)。 Firefox(等)使用 param 元素,但 IE 从属性中读取。两次指定所有内容很烦人,但这就是你必须做的,除非你使用类似于 swfobject 的东西可以为您完成此操作(强烈推荐)。

基于使用 swfobject 进行更新:

听起来您实际上是在尝试使用 jQuery.clone 重新实现 swfobject.embedSWF。我确信它可以工作,但我建议您坚持使用 swfobject 进行 Flash 嵌入,使用 jQuery 进行 DOM。我将使用以下结构:

function embedAudioPlayer(replaceElemIdStr, audioFile) {
    // customize these options for the audio player you're using
    swfobject.embedSWF(
        "yourplayer.swf", 
        replaceElemIdStr, 
        width, 
        height, 
        "9.0.115", 
        "expressInstall.swf",
        {
            soundFile = audioFile
        });
}

$("select[name='variation3']").live('change', function() {
    // ...
    var audioFile = path + $(this).find(':selected').val() + '.mp3';
    var uniqueId = 'audio-' + +new Date;
    player.replaceWith('<div id="+uniqueId+"/>');
    embedAudioPlayer(uniqueId, audioFile);
});
  1. 创建一个 embedAudioPlayer 函数,并将其用于初始页面加载和响应页面事件时的所有操作。
  2. 响应页面事件时,使用 jQuery 来确定 soundFile url 和应创建新音频播放器的目标元素。

Firefox and everything but IE uses the Netscape Plugin Application Programming Interface (NPAPI) for Flash. Firefox (et al.) use the param elements but IE reads from the attributes. It's annoying specifying everything twice but that's what you have to do unless you're using something like swfobject that does it for you (highly recommended) .

Updated based on using swfobject:

Sounds like you're essentially trying to reimplement swfobject.embedSWF Using jQuery.clone. I'm sure it could be made to work but I suggest you stick to swfobject for Flash embedding and jQuery for the DOM. I'd use the following structure:

function embedAudioPlayer(replaceElemIdStr, audioFile) {
    // customize these options for the audio player you're using
    swfobject.embedSWF(
        "yourplayer.swf", 
        replaceElemIdStr, 
        width, 
        height, 
        "9.0.115", 
        "expressInstall.swf",
        {
            soundFile = audioFile
        });
}

$("select[name='variation3']").live('change', function() {
    // ...
    var audioFile = path + $(this).find(':selected').val() + '.mp3';
    var uniqueId = 'audio-' + +new Date;
    player.replaceWith('<div id="+uniqueId+"/>');
    embedAudioPlayer(uniqueId, audioFile);
});
  1. Create a embedAudioPlayer function and use it for everything both at initial page load and in response to page events.
  2. When responding to page events use jQuery to determine the soundFile url and the destination element where a new audio player should be created.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文