JSFiddle - React, Tailwind, and code Playground

by sarathsprakash

HTML

<div id="entries"></div>

JavaScript

function getdata(url) {
    var a = url;
    var q = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + a + '" and xpath="//title|//head/meta"') + '&format=json&callback=?';
    var reg = /^.*(jpeg|png|gif|bmp)/;
    var reg1 = /^(https?|ftp):\/\/.*(jpeg|png|gif|bmp)/;
    $.ajax({
        url: q,
        dataType: "jsonp",
        success: function (data) {
            var result = {};
            if (data.query.results.title) {
                result.title =data.query.results.title;
                  $('#entries').append('<div id="title">' + result.title + '</div>');
            }           
            $.each(data.query.results.meta, function (key, val) {
                if (val.content) {
                    // description
                    if (val.name == 'description') {
                        result.description = val.content;
                        $('#entries').append('<div id="description">' + result.description + '</div>');
                    }

                    if (reg1.test(val.content)) {
                        result.image = val.content;
                        $('#entries').append('<img id="image" src="' + result.image + '" style="max-width:200px;max-height:200px;width:auto;height:auto;"/>');
                    } else if (reg.test(val.content)) {
                        result.image = 'http://www.google.com' + val.content;
                        $('#entries').append('<img id="image" src="' + result.image + '" style="max-width:200px;max-height:200px;width:auto;height:auto;"/>');
                    }
                }
            });
        },
    });
}

getdata("http://in.movies.yahoo.com/news/");