[英]preview of content from url link of souncloud using input text
I want to to copy the link https://soundcloud.com/weezer/weezer-king-of-the-world to input box. 我想将链接https://soundcloud.com/weezer/weezer-king-of-the-world复制到输入框。 It needs to show the preview of the link.
它需要显示链接的预览。 I have tried using iframe but it didnt work as i wanted.
我曾尝试使用iframe,但没有按我的要求工作。 You could use following html code with id and other necessary info for reference
您可以使用以下具有id和其他必要信息的html代码作为参考
<input id="song-link" placeholder="Paste Soundcloud link here" name="song_link" type="text">
</div>
<iframe width="100%" height="166" scrolling="no" frameborder="no" src="" id="soundcloud_iframe"></iframe>
<script type="text/javascript">
$('#song-link').on('paste', function () {
var element = this;
setTimeout(function () {
var text = $(element).val();
// do something with text
document.getElementById("soundcloud_iframe").src = text;
}, 1);
});
</script>
I did the googling for you. 我为您做了谷歌搜索。 There is a very well documented sdk/api for soundcloud, which even helps with the embedding: https://developers.soundcloud.com/docs/api/sdks#embedding
有一个关于Soundcloud的有据可查的sdk / api,甚至可以帮助嵌入: https : //developers.soundcloud.com/docs/api/sdks#embedding
with this its very easy to embbed an soundcloud link: https://jsfiddle.net/orac4bv5/2/ 与此非常容易嵌入音云链接: https ://jsfiddle.net/orac4bv5/2/
$('#song-link').change(function () { var link = $('#song-link').val(); SC.oEmbed(link, { element: document.getElementById('putTheWidgetHere') }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://connect.soundcloud.com/sdk/sdk-3.1.2.js"></script> <input id="song-link" placeholder="Paste Soundcloud link here" name="song_link" type="text"> <div id="putTheWidgetHere"></div>
i'm not sure why it works because I did not specify a api key, but you should defenetly register a api key for your site. 我不确定为什么会这样,因为我没有指定api密钥,但是您应该为您的网站默认注册一个api密钥。
you may want to change it back to paste, atm just hit enter to trigger the "change" event. 您可能需要将其更改回粘贴,atm只需按Enter即可触发“更改”事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.