加载Soundcloud嵌入式播放器OnClick无法在FireFox中工作

时间:2015-03-28 18:23:11

标签: javascript html firefox onclick soundcloud

网站:https://www.buybeatsfast.com/beats/

点击" Play Beat"图像应加载该轨道的Soundcloud播放器并自动播放。这适用于Chrome,但在Firefox中,它只会将您带到Soundcloud音轨页面。我在Windows XP和Windows 8上对此进行了测试,它在Firefox中根本不起作用,控制台上没有任何错误,所以我不知道问题是什么,我不是这段代码的作者,我实际上在这里发现了它。

这是html:

<div class="tempsc"><a href="https://soundcloud.com/rockitpro/imstillherehook" class="scload"><span class="playbeat"><span class="icon-play-sign playbeaticon"></span> Play Beat</span></a></div>

这是js:

/*SOUNDCLOUD CLICK TO PLAY*/
var formatPlayer    = '&iframe=true';
formatPlayer   += '&color=3498DB';
formatPlayer   += '&buying=false';
formatPlayer   += '&download=false';
formatPlayer   += '&show_playcount=false';
formatPlayer   += '&show_reposts=false';
formatPlayer   += '&show_user=false';
formatPlayer   += '&show_comments=false';
formatPlayer   += '&liking=false';
formatPlayer   += '&hide_related=true';
formatPlayer   += '&sharing=false';
formatPlayer   += '&maxheight=125';
formatPlayer   += '&auto_play=true'; // Play once user clicks link!
formatPlayer   += '&show_artwork=true';
//LOAD IFRAME ON CLICK
$('.scload').click(function(){
event.preventDefault();
var $link = $(this);
var getJSONstring = 'https://soundcloud.com/oembed?format=js&amp;url=' + $link.attr('href') + formatPlayer;
//Replace contents
$.getJSON(getJSONstring + '&amp;callback=?', function(response) {
var widget = response.html;
var src = $(widget).attr('src');
widget = $(widget).attr('src', src.replace('?visual=true', '?visual=false')); // Update iFrame src
$link.replaceWith(widget); }); });

1 个答案:

答案 0 :(得分:0)

固定。忘了将event传入click函数。现在可以在Firefox中使用。

/*SOUNDCLOUD CLICK TO PLAY*/
var formatPlayer    = '&iframe=true';
formatPlayer   += '&color=3498DB';
formatPlayer   += '&buying=false';
formatPlayer   += '&download=false';
formatPlayer   += '&show_playcount=false';
formatPlayer   += '&show_reposts=false';
formatPlayer   += '&show_user=false';
formatPlayer   += '&show_comments=false';
formatPlayer   += '&liking=false';
formatPlayer   += '&hide_related=true';
formatPlayer   += '&sharing=false';
formatPlayer   += '&maxheight=125';
formatPlayer   += '&auto_play=true'; // Play once user clicks link!
formatPlayer   += '&show_artwork=true';
//LOAD IFRAME ON CLICK
$('.scload').click(function (e) {
e.preventDefault();
var $link = $(this);
var getJSONstring = 'https://soundcloud.com/oembed?format=js&amp;url=' + $link.attr('href') + formatPlayer;
//Replace contents
$.getJSON(getJSONstring + '&amp;callback=?', function(response) {
var widget = response.html;
var src = $(widget).attr('src');
widget = $(widget).attr('src', src.replace('?visual=true', '?visual=false')); // Update iFrame src
$link.replaceWith(widget); }); });