2011-03-05 100 views
0

以下是一個簡單的代碼,讓JavaScript在彈出窗口中打開soundcloud音頻播放器。它在firefox和chrome中完美工作,但在IE7中不起作用;它只是顯示一個空白的黑屏。有誰知道爲什麼?簡單的Javascript不工作在IE中,在火狐工作

我得到一個黃色的下拉框,上面寫着「幫助保護.. IE已經限制這個網頁運行腳本或ActiveX控件....」即使當我點擊它並說允許,soundcloud播放器仍然沒有' t出現。

<HTML> 
<HEAD> 

<script type='text/javascript'> 

    function fetchArguments() { 
     var arg = window.location.href.split("?")[1].split("&"); // arguments 

     var len = arg.length; // length of arguments 
     var obj = {}; // object that maps argument id to argument value 
     var i; // iterator 
     var arr; // array 


    for (var i = 0; i < len; i++) { 
     arr = arg[i].split("="); // split the argument 
     obj[arr[0]] = arr[1]; // e.g. obj["song"] = "3" 
    } 
    return obj; 
} 

    function loadTitle() { 
     var args = fetchArguments(); 
     document.title = "Audio: Accidential Seabirds - " + args["name"]; 
    } 

    function loadMusic() { 
     var args = fetchArguments(); 

     var height = "100"; 
     object = document.createElement("object"); 
     object.height = height; 
     object.width = "100%"; 

     nameParam = document.createElement("param"); 
     nameParam.name="movie"; 
     nameParam.value ="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F" + args["song"]; 

     scriptParam = document.createElement("param"); 
     scriptParam.name="allowscriptaccess"; 
     scriptParam.value="always"; 

     embedTag = document.createElement("embed"); 
     embedTag.allowscriptaccess="always"; 
     embedTag.height= height; 
     embedTag.src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F" + args["song"]; 
     embedTag.type="application/x-shockwave-flash"; 
     embedTag.width="100%"; 


     object.appendChild(nameParam); 
     object.appendChild(scriptParam); 
     object.appendChild(embedTag); 

     document.getElementsByTagName("body")[0].appendChild(object); // we append the iframe to the document's body 

     window.innerHeight=100; 
     window.innerWidth=600; 
     self.focus(); 

    } 
</script> 

    <script type='text/javascript'> 
     loadTitle(); 
    </script> 

</HEAD> 
<BODY bgcolor="#000000" topmargin="0" marginheight="0" leftmargin="0" marginwidth="0"> 
    <center> 
     <script type='text/javascript'> 
      loadMusic(); 
     </script> 
    </center> 
</BODY> 
</HTML> 

的代碼來調用這個窗口可能是

function PopupMusic(song, name) { 
    var ptr = window.open("musicplayer.htm?song="+song+"&name='"+name+"'", song, "resizable='false', HEIGHT=90,WIDTH=600"); 
    if(ptr) ptr.focus(); 
    return false; 
} 

<a href="javascript:listen()" onclick="javascript:PopupMusic('7537509', 'the appearance of new animals')">Listen</a> 

回答

0

我想通了。您需要使用setAttributeFunction:

function loadVideo() { 
     var args = fetchArguments(); 
     var videoFrame = document.createElement("iframe"); 
     videoFrame.setAttribute('id', 'videoFrame'); 
     videoFrame.setAttribute('title', 'YouTube video player'); 
     videoFrame.setAttribute('class', 'youtube-player'); 
     videoFrame.setAttribute('type', 'text/html'); 
     videoFrame.setAttribute('width', args["width"]); 
     videoFrame.setAttribute('height', args["height"]); 
     videoFrame.setAttribute('src', 'http://www.youtube.com/embed/' + args["vid"]); 
     videoFrame.setAttribute('frameborder', '0'); 
     videoFrame.allowFullScreen; 

     document.getElementsByTagName("body")[0].appendChild(videoFrame); // we append the iframe to the document's body 

     self.focus(); 

    } 
0

下面的代碼工作正常在IE/FF/Chrome瀏覽器:

<script type='text/javascript'> 
var musicSrc = 'http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Frjchevalier%2Fjust-one-day-ft-deni-hlavinka&amp;color=3b5998&amp;auto_play=true&amp;show_artwork=false'; 
document.write('<object type="application/x-shockwave-flash" width="100%" height="100%" data="'+musicSrc+'"><param name="movie" value="'+musicSrc+'" /></object>'); 
</script> 
+0

沒有文件撰寫打開網頁多達攻擊?例如,如果他們製作了musicSrc = wefw「> JoshuaD 2011-03-05 16:21:52

+0

document.write僅供您展示,您可以將其更改爲任何您想要的內容,例如innerHTML。 – ahgood 2011-03-05 23:24:12