0

I am developing an app using node-webkit. I have an iframe which loads a webpage. The webpage has an unordered list and I would like to get a trigger if an element in the unordered list changes.

<iframe id="app" src="https://www.somewebsite.com/" nwdisable nwfaketop></iframe>

The unordered list does not have a class name and its only tag is data-reactid="XYZ". However the first item in the unordered list always has a class name: .abc

From another SO question (Call jquery function when <ul> content change) , I found how to trigger a function if there is a change:

! function () {
    var ulContent;
    $(document).ajaxStop(function () {
        var $ul = $('.abc');
        if(ulContent !== $ul.html()){
            ulContent = $ul.html();
            $ul.trigger('contentChanged');
        }
    });
}();

$('.abc').on('contentChanged',function(){alert('UL content changed!!!');});

However I believe right now, the script is looking for the class .abc in the current page's source code rather than that of the iframe.

To extract the source code of the iframe I wrote:

innerBody = document.getElementById('app').contentWindow.document.body.innerHTML;

What would be the way to make the ajax function look into the iframe's source code? Also what does the ! signify in the ajax function?

Community
  • 1
  • 1
user1692342
  • 5,007
  • 11
  • 69
  • 128
  • It should work if iFrame on same domain: `$(document.getElementById('app').contentWindow.document.body).find('ul/*or any more specific selector*/');` But as jQuery is always called on parent document, and because i don't know how you update the UL inside iframe content (using ajax from iframe or from parent), this would need more testing i guess – A. Wolff May 30 '15 at 15:17
  • the iFrame is of another website. Could Yahoo pipes help in that case? – user1692342 May 30 '15 at 15:18
  • Well, I don't know yahoo pipes but you could proxified it server side (maybe what is doing yahoo pipes, don't know). Now what makes change inside UL? An ajax request? I'm really not sure this logic using `$.ajaxStop()` method would work in your case. Maybe provide online link where this can be tested (optimally a jsFiddle replicating issue) – A. Wolff May 30 '15 at 15:23
  • @A. Wolff possible to discuss over chat? http://chat.stackoverflow.com/rooms/79203/js-discussion – user1692342 May 30 '15 at 15:26
  • you'd have better to provide all relevant code in question itself – A. Wolff May 30 '15 at 15:33
  • @A.Wolff Not sure how to get this running on JSfiddle. However my external website is www.messenger.com and what I am trying to achieve is, check in the list of chats, if there is a change in the first message. If there is a change in the first element in the list, it indicates a new message has arrived and I should extract the text – user1692342 May 30 '15 at 16:29

0 Answers0