snipt

Ctrl+h for KB shortcuts

JavaScript

Add wmode to Youtube video embed URL with jQuery

1
2
3
4
5
6
7
//iframe z-index fix
$(document).ready(function ()
    $('iframe').each(function()
        var url = $(this).attr("src")
    $(this).attr("src",url+"?wmode=transparent")
    );
);
https://snipt.net/embed/af7faea7331d76b501d0be840c08d756/
https://snipt.net/raw/af7faea7331d76b501d0be840c08d756/
af7faea7331d76b501d0be840c08d756
js
JavaScript
7
2016-09-30T09:09:54
True
False
False
/api/public/snipt/42900/
add-wmode-to-fix-youtube-iframe-zindex-with-jquery
<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> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c1">//iframe z-index fix</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;iframe&#39;</span><span class="p">).</span><span class="nx">each</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> </span><span id="L-4"><a name="L-4"></a> <span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s2">&quot;src&quot;</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s2">&quot;src&quot;</span><span class="p">,</span><span class="nx">url</span><span class="o">+</span><span class="s2">&quot;?wmode=transparent&quot;</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">);</span> </span><span id="L-7"><a name="L-7"></a><span class="p">);</span> </span></pre></div> </td></tr></table>
embed, iframe, jquery, video, wmode, youtube, zindex

JavaScript

redirect if not in iframe

1
2
3
4
5
 if (window===window.top) {

          top.location.href ="http://google.com";

        };
https://snipt.net/embed/fc2df1b718a5d9c93d2e621a7ab6a77e/
https://snipt.net/raw/fc2df1b718a5d9c93d2e621a7ab6a77e/
fc2df1b718a5d9c93d2e621a7ab6a77e
js
JavaScript
5
2016-09-27T23:45:03
True
False
False
/api/public/snipt/35810/
redirect-if-not-in-iframe
<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> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a> <span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="o">===</span><span class="nb">window</span><span class="p">.</span><span class="nx">top</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a> <span class="nx">top</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">href</span> <span class="o">=</span><span class="s2">&quot;http://google.com&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> <span class="p">};</span> </span></pre></div> </td></tr></table>
facebook, iframe, javascript, redirect

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/
https://snipt.net/raw/16d7d5b553b510f2d81738bb441d57d5/
16d7d5b553b510f2d81738bb441d57d5
js
JavaScript
6
2016-09-30T20:42:32
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 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
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.