0

So I have a large amount of html that is served up by a web service that i need to display. The problem is the this html very often contains many iframe links to youtube videos. I've counted one that contained around 20.

These are not small amounts of html and I'm trying to weigh efficiency here. Right now those 20 iframes are slowing the app down to a crawl.

What would be more efficient? Stopping the iframes from loading ( which I'm unsure of how to do)

-or-

Parse through the html and remove the iframes and replacing them with the link to the video within them, thus allowing the user to open up the video, but not having to worry about the iframe. This can be done before they are displayed and may increase load time a bit, but would reduce http calls (i think)

-or-

Any suggestions?

Thanks

(Also I am not using JQuery nor is it available)

4

1 回答 1

0

所以这是我发现的方法有点工作。唯一的问题是我注意到嵌套在表中的 iframe 并不总是能找到它们,如果有人有替代方法,请告诉我。

parseMessage: function(json) {
      var container = document.createElement('div');
      container.id = 'tempContainer';
      document.body.appendChild(container);
      container.innerHTML = json[4];
      var iframes = container.getElementsByTagName("iframe");
      if (iframes.length != 0)
      {
        for (var a = 0; a < iframes.length; a += 1) {
            var sourcetemp = iframes[a].src;
            var parent = iframes[a].parentNode;
            var newNode = document.createElement('a');
            newNode.href = sourcetemp;
            newNode.innerHTML = sourcetemp;
            parent.removeChild(iframes[a]);
            parent.appendChild(newNode);
        }
      }
      document.body.removeChild(container);
      return container.innerHTML;
      //mydiv = json[4].getElementById('FirstDiv');
      //while ( mydiv.firstChild ) mydiv.removeChild( mydiv.firstChild );
  },
于 2012-09-21T18:43:12.760 回答