snipt

Ctrl+h for KB shortcuts

JavaScript

Using jquery to call an iframe's parent method

1
2
3
4
// From inside an iframe
(function($) {
    parent.$("#element_in_parent").trigger("event");
} (window.jQuery));
https://snipt.net/embed/16d7d5b553b510f2d81738bb441d57d5/
/raw/16d7d5b553b510f2d81738bb441d57d5/
16d7d5b553b510f2d81738bb441d57d5
js
JavaScript
6
2019-08-19T18:15:58
True
False
False
/api/public/snipt/34251/
using-jquery-to-call-an-iframes-parent-method
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">// From inside an iframe</span> </span><span id="L-2"><a name="L-2"></a><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">$</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">parent</span><span class="p">.</span><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#element_in_parent&quot;</span><span class="p">).</span><span class="nx">trigger</span><span class="p">(</span><span class="s2">&quot;event&quot;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">jQuery</span><span class="p">));</span> </span></pre></div> </td></tr></table>
iframe, jquery, parent