snipt

Ctrl+h for KB shortcuts

JavaScript

Alternative for taget="_blank"

1
2
3
4
    $('a').not('[href*="'+ window.location.host +'"]').click(function(e) {
        e.preventDefault();
        window.open(this.href, '_blank');
    });
https://snipt.net/embed/77a874592ac5e994e6ee4c0ca69e3275/
/raw/77a874592ac5e994e6ee4c0ca69e3275/
77a874592ac5e994e6ee4c0ca69e3275
js
JavaScript
4
2019-07-19T03:10:06
True
False
False
/api/public/snipt/34929/
alternative-for-taget_blank
<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="nx">$</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">).</span><span class="nx">not</span><span class="p">(</span><span class="s1">&#39;[href*=&quot;&#39;</span><span class="o">+</span> <span class="nb">window</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">host</span> <span class="o">+</span><span class="s1">&#39;&quot;]&#39;</span><span class="p">).</span><span class="nx">click</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">window</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">href</span><span class="p">,</span> <span class="s1">&#39;_blank&#39;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">});</span> </span></pre></div> </td></tr></table>
alternative, blank, javascript, target