0

I'm using a plugin called vuukle on wordpress and load a comment section. Inside that section I need to replace an image url. But seems like code is not working without any error. This is my code,

$('.bXLoAM').each(function (i, obj) {
    var str = obj.href;
    str = str.replace("https://api.vuukle.com/stats/External?source=talk_of_town&url=", "");
    str = str.replace("https://api.vuukle.com/stats/External?source=talk_of_town&url=", "");

    $.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent(str) +
        '&callback=?',
        function (data) {
            console.log(data.contents);
            var s = data.contents;
            var htmlObject = $(s);

            $(obj.querySelector('img')).attr("src", htmlObject.find('.attachment-single_thumb')[0].src);
        });
});

And below is the code in iframe with parent div. And think iframe is loaded with ajax via plugin.

<div id="vuukle-comments" class="commentBoxDiv" style="display: flex;flex-direction: column;width: 100%;align-items: stretch;">
    <div class="vuukle-ads" style="display: block; height: auto; margin: 10px auto; text-align: center; clear: both; width: 100%; max-width: 100%; overflow: hidden;">
        <div id="div-gpt-ad-1497448474263-1" data-google-query-id="CLSC6ZfJz-MCFQoZcgodPH8Fow">
            <div id="google_ads_iframe_/213794966/vuukle-widget/lankabusinessonline.com_0__container__" style="border: 0pt none;"><iframe id="google_ads_iframe_/213794966/vuukle-widget/lankabusinessonline.com_0" title="3rd party ad content" name="google_ads_iframe_/213794966/vuukle-widget/lankabusinessonline.com_0" scrolling="no" marginwidth="0" marginheight="0" style="border: 0px none; vertical-align: bottom;" srcdoc="" data-google-container-id="1l" data-load-complete="true" width="300" height="0" frameborder="0"></iframe></div>
        </div>
    </div>
    <iframe src="https://cdn.vuukle.com/widgets/index.html?apiKey=mykey&amp;host=lankabusinessonline.com&amp;articleId=135613&amp;author=LBO&amp;img=&amp;lang=en&amp;tags=ETL%20Colombo%20denies%20claims%20as%20the%20importer%20of%20waste%20cargo%2C%20lbo%2C%20lbo.lk&amp;title=&amp;url=https%3A%2F%2Fwww.lankabusinessonline.com%2Fetl-colombo-denies-claims-as-the-importer-of-waste-cargo%2F&amp;color=%23108ee9&amp;darkMode=false&amp;emotesEnabled=true&amp;firstImg=&amp;secondImg=&amp;thirdImg=&amp;fourthImg=&amp;fifthImg=&amp;sixthImg=&amp;d=false&amp;realtime=false&amp;l_d=false&amp;totWideImg=false&amp;link=https%3A%2F%2Fwww.%5Burl%5D&amp;hideArticles=false&amp;maxChars=3000&amp;commentsToLoad=5&amp;toxicityLimit=80&amp;spamLimit=90&amp;gr=false&amp;hideCommentBox=false&amp;hideCommentBoxWithButton=false&amp;wpSync=false&amp;fAuth=true&amp;gAuth=true&amp;tAuth=true&amp;dAuth=false&amp;vuukleAuth=false&amp;passwordAuth=false" style="width: 100%; min-width: 100%; overflow: hidden; order: 1; height: 731px;" name="v-comments" id="v-comments" scrolling="no" height="0" frameborder="0"></iframe>
</div>
vimuth
  • 5,064
  • 33
  • 79
  • 116
  • I am guessing your iframe is not loaded, paste your JS code to console and see if it is working, if it doesn't work, try to inspect iframe then check the code again, if it works, then it's loading issue, your code is running before the frame loads. If that's the case, a secondary solution will be an auto click on an element on the screen that has iframe then run your function – Hindreen Jul 25 '19 at 08:59
  • 1
    I think it relate to https://stackoverflow.com/questions/40318509/modifying-the-html-content-of-an-iframe-using-jquery – dungmidside Jul 25 '19 at 09:12

0 Answers0