【发布时间】:2014-08-26 20:50:12
【问题描述】:
在 JavaScript 中有没有办法从 URL 中获取歌曲名称?
我使用了<iframe>标签,但是我无法获取soundcloud的文档并找到文档的标题。
HTML:
<span id="iframe_container"></span>
<span id="name"></span>
JS:
var video_url_new = '<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/81619639&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&visual=true"></iframe>';
var link_new;
//play song
play();
function play(){
link_new = video_url_new.replace("></iframe>", " id='i_song_name_i'></iframe>").replace("auto_play=false", "auto_play=true").replace(' width="100%" height="450" scrolling="no" frameborder="no"', '');
document.getElementById("iframe_container").innerHTML = link_new;
// And here's the problem:
document.getElementById("name").innerText = document.getElementById("i_song_name_i").contentWindow.document.getElementsByTagName("title")[0].innerText;
}
...我的浏览器返回此错误:
错误:访问属性“文档”的权限被拒绝
我知道 soundcloud 不允许在框架中获取文档,所以我想问一下;网站(或类似网站)是否包含没有 iframe 保护的歌曲信息?
【问题讨论】:
-
示例 html iframe 嵌入是什么样的?请用一些标记更新您的问题。
-
@Grevling 感谢您的编辑! (我英语说得不太好:})
标签: javascript iframe soundcloud