开发者

Identify embedded code in textbox using jQuery

I recently found out about oEmbed which is "a fomat for allowing an embedded representation of a URL" basically you enter the url of a youtube video that you like and oEmbed will return the embedded code of the video in this page.

I want to give my users the option to either enter a url or embed code in a textbox. If is embed code it should leave the text as it is, but if it is a url it should get the embed code from oEmbed.

My problem is the following: how do I identify if the user paste an embed code or a 开发者_开发百科url?


$(document).ready(function() {
    $('#embedCode').bind('paste', function(e) { 
        // time out until the value has been pased to the textbox
        setTimeout(function() {
            var code = $('#embedCode').val();
            var tagCount = 0;

            // Identify embedded code here

            if(tagCount == 0) {
                alert('LINK');
            }
            else {
                alert('EMBED');
            }
        }, 100);    

    });

});

I was thinking to add a method to count the the number of valid tags such as object and param but have had no luck trying to do this.

Any ideas?

Thank you


//Using a youtube video page as an example:

if( $('#embedForm input').val().toLowerCase().indexOf('<object') > -1 )
{
    //input value has an OBJECT tag
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜