Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get the HTML returned by jquery-oembed-all as a string?
    primarykey
    data
    text
    <p>I'm testing <a href="https://github.com/starfishmod/jquery-oembed-all" rel="nofollow noreferrer">jquery-oembed-all</a> as a solution for <a href="https://stackoverflow.com/questions/19806767/how-to-run-oembed-on-text-pasted-into-wysihtml5-composer">another question</a> I have asked. The script is a small javascript file loaded in the page and provides the <code>oembed</code> function for fetching media embed code.</p> <p>I'm getting the oEmbed iframe back from a link easily like this:</p> <pre><code>&lt;script&gt; $(function(){ tag = $(document.createElement('div')).oembed('https://vimeo.com/40179668'); $('.header').append(tag); }); &lt;/script&gt; </code></pre> <p>This works great and adds the oEmbed-generated iframe element to the <code>.header</code> on the page. However I need the generated HTML as a string. Poking around in <code>tag[0].outerHTML</code> and even <code>tag[0].parent()[0].outerHTML</code> just revealed <code>tag</code> to be the original empty <code>div</code> created in the script, yet it clearly has all of the embed code because the embedded video loads on the page.</p> <p>How do I get the HTML returned by the <code>oembed</code> function as a text string? Do I need to traverse the DOM from the created <code>div</code> tag to find it?</p> <p><strong>EDIT:</strong> I added some alerts and it's all to do with timing. Since it's a network call the oEmbed function hasn't come back with an HTML block by the time I'm querying the <code>outerHTML</code>.</p> <p><strong>EDIT 2:</strong> Looks like this can be solved with JS callbacks since the oEmbed call is asynchronous. When I get time to look for a solution I'll post it back here as an answer.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload