2011-12-16 68 views
0

我需要檢測使用JavaScript的網頁內的MP3鏈接,並替換文本具有:檢測和編輯MP3鏈接

<embed type="application/x-shockwave-flash" 
src="http://www.google.com/reader/ui/3247397568-audio-player.swf? 
audioUrl=http://LINK" width="400" height="27" 
allowscriptaccess="never" quality="best" bgcolor="#ffffff" 
wmode="window" flashvars="playerMode=embedded" /> 

與MP3的URL值?

我該怎麼辦?

+4

感謝您的分享。問題是什麼? – Dutchie432 2011-12-16 16:38:47

回答

1
[].map.call(document.links, function(v){ 

    if(v.href.indexOf(".mp3") === v.href.length - 4) { 
     return '<embed type="application/x-shockwave-flash" ' + 
      'src="http://www.google.com/reader/ui/3247397568-audio-player.swf?' + 
      'audioUrl='+encodeURIComponent(v.href)+' width="400" height="27" ' + 
      'allowscriptaccess="never" quality="best" bgcolor="#ffffff" ' + 
      'wmode="window" flashvars="playerMode=embedded" />'; 
    } 

    return ""; 

}).join(""); 

http://jsfiddle.net/e5DSU/2/

頁面上的以下鏈接:

<a href="/asd/asd/asd.mp3"></a> 
<a href="/asd/asd/asd.mp3"></a> 
<a href="/asd/asd/asd.mp3"></a> 

得出:

<embed type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=http%3A%2F%2Ffiddle.jshell.net%2Fasd%2Fasd%2Fasd.mp3 width="400" height="27" allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" /> 
<embed type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=http%3A%2F%2Ffiddle.jshell.net%2Fasd%2Fasd%2Fasd.mp3 width="400" height="27" allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" /> 
<embed type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=http%3A%2F%2Ffiddle.jshell.net%2Fasd%2Fasd%2Fasd.mp3 width="400" height="27" allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" /> 
+0

如何使它在移動瀏覽器上單獨保留鏈接(或創建「播放音頻」鏈接) – JoshMWilliams 2011-12-17 00:25:06

+0

幫助這不起作用....任何想法? – JoshMWilliams 2011-12-21 07:19:32

0

http://jsfiddle.net/ZVzF6/

$('a').each(function(){ 
    var src=$(this).attr('href'); 
    var a = src.split('.'); 
    var ext = a[a.length-1]; 
    if (ext=='mp3'){ 

     var html = '<embed type="application/x-shockwave-flash"                   
        src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=' + encodeURIComponent(src) + '" 
        width="400" 
        height="27" allowscriptaccess="never" quality="best" 
        bgcolor="#ffffff" wmode="window" 
        flashvars="playerMode=embedded" />'; 

     $(html).insertAfter($(this)); 
     $(this).remove();  
    } 
});