Convert all http:// to https:// using jQuery or Javascript
<p>I'm trying to covert links in src tags to <code>https://</code>. More accurately Youtube iframes. For example:</p>

<pre><code>&lt;iframe width='650' height='365' src="http://www.youtube.com/embed/y9kBixgYKzw" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;
</code></pre>

<p>I tried the  below code with no luck:</p>

<pre><code>function RedirNonHttps() {
    if (location.src.indexOf("https://") == -1) {
        location.src = location.src.replace("http://", "https://");
    }
}
</code></pre>

<pre class="lang-html prettyprint-override"><code>&lt;body onload="RedirNonHttps();"&gt;
</code></pre>

<p>Can someone point me out the correct way to do this?</p>