0

So i've been looking around for a while for a possible solution to make a javascript, jquery which searches in the iFrame for a certain class or id element. Then takes out the html inside of it. (example. <a id="link">Here's a link</a> ). then makes it a string out of it and also replay this function every 5 second or so. Is there anyone who know a good solution to this or a tutorial?

I've tried the function var inf = $('#iframeid').contents().find('#theid').html();but it didn't gave any success.

alex
  • 479,566
  • 201
  • 878
  • 984
user1925371
  • 33
  • 2
  • 6
  • 1
    is theiframe source at the same domain? See http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe – Joshua - Pendo Mar 30 '13 at 00:42

1 Answers1

0

Try this:

function GetFrameData() {
    var $MyFrame = $("#iframeid");

    // You need to wait for the iFrame content to load first
    // So, that the click events work properly
    $MyFrame.load(function () {
        var frameBody = $MyFrame.contents().find('body');
        var inf = frameBody.find('#theid').html();
    });
}

// Call the function every 5 seconds
setInterval(GetFrameData, 5000);
palaѕн
  • 72,112
  • 17
  • 116
  • 136