snipt

Ctrl+h for KB shortcuts

JavaScript

hashbang stylesheet change

1
2
3
4
5
// Swaps out the screen stylesheet for a print stylesheet
if (window.location.hash == '#print=true') {
	var printcssuri = $('link[media=print]:first').attr('href');
	$('link[media=screen]:first').attr('href', printcssuri);
}

Description

Originally created to pull in some terms on the Washington Brown site in to an iframe in an order form
https://snipt.net/embed/8316e7f10fd7cefa41accd90fe1f4036/
/raw/8316e7f10fd7cefa41accd90fe1f4036/
8316e7f10fd7cefa41accd90fe1f4036
js
JavaScript
5
2019-06-19T02:40:21
True
False
False
Mar 18, 2014 at 03:12 AM
/api/public/snipt/122666/
hashbang-stylesheet-change
<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></span><span id="L-1"><a name="L-1"></a><span class="c1">// Swaps out the screen stylesheet for a print stylesheet</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">hash</span> <span class="o">==</span> <span class="s1">&#39;#print=true&#39;</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="kd">var</span> <span class="nx">printcssuri</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;link[media=print]:first&#39;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;href&#39;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;link[media=screen]:first&#39;</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;href&#39;</span><span class="p">,</span> <span class="nx">printcssuri</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
CSS, jQuery, link, meta, theme