snipt

Ctrl+h for KB shortcuts

JavaScript

Disable all forms on a page

1
2
3
4
5
6
7
8
  <script>
    for(i=0; i < document.forms.length; i++) {
      f = $(document.forms[i].id);
      if (f != null) {
        Form.disable(f);
      }
    }
  </script>
https://snipt.net/embed/da80f76e5134380f555112cc93d75687/
/raw/da80f76e5134380f555112cc93d75687/
da80f76e5134380f555112cc93d75687
js
JavaScript
8
2019-06-12T22:38:48
True
False
False
/api/public/snipt/1956/
disable-all-forms-on-a-page
<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> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a> <span class="o">&lt;</span><span class="nx">script</span><span class="o">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">for</span><span class="p">(</span><span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nb">document</span><span class="p">.</span><span class="nx">forms</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">f</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">forms</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">id</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">if</span> <span class="p">(</span><span class="nx">f</span> <span class="o">!=</span> <span class="kc">null</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">Form</span><span class="p">.</span><span class="nx">disable</span><span class="p">(</span><span class="nx">f</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><span id="L-8"><a name="L-8"></a> <span class="o">&lt;</span><span class="err">/script&gt;</span> </span></pre></div> </td></tr></table>
forms, html, javascript, prototype

JavaScript

jQuery Interpreter Bookmarklet

javascript:(function()%20{head%20=%20document.getElementsByTagName(%27head%27)[0];jash_script%20=%20document.createElement(%27script%27);jash_script.src%20=%20%27http://www.billyreisinger.com/jash/source/latest/Jash.js%27;jash_script.type%20=%20%27text/javascript%27;jquery_script%20=%20document.createElement(%27script%27);jquery_script.src%20=%20%27http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.js%27;jquery_script.type%20=%20%27text/javascript%27;head.appendChild(jquery_script);head.appendChild(jash_script);})();
https://snipt.net/embed/f4ffd940ab5e4c09f83d06ba093f715f/
/raw/f4ffd940ab5e4c09f83d06ba093f715f/
f4ffd940ab5e4c09f83d06ba093f715f
js
JavaScript
1
2019-06-18T13:14:05
True
False
False
/api/public/snipt/1778/
jquery-interpreter-bookmarklet
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</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">javascript</span><span class="o">:</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span><span class="o">%</span><span class="mi">20</span><span class="p">{</span><span class="nx">head</span><span class="o">%</span><span class="mi">20</span><span class="o">=%</span><span class="mi">20</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="o">%</span><span class="mi">27</span><span class="nx">head</span><span class="o">%</span><span class="mi">27</span><span class="p">)[</span><span class="mi">0</span><span class="p">];</span><span class="nx">jash_script</span><span class="o">%</span><span class="mi">20</span><span class="o">=%</span><span class="mi">20</span><span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="o">%</span><span class="mi">27</span><span class="nx">script</span><span class="o">%</span><span class="mi">27</span><span class="p">);</span><span class="nx">jash_script</span><span class="p">.</span><span class="nx">src</span><span class="o">%</span><span class="mi">20</span><span class="o">=%</span><span class="mi">20</span><span class="o">%</span><span class="mi">27</span><span class="nx">http</span><span class="o">:</span><span class="c1">//www.billyreisinger.com/jash/source/latest/Jash.js%27;jash_script.type%20=%20%27text/javascript%27;jquery_script%20=%20document.createElement(%27script%27);jquery_script.src%20=%20%27http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.js%27;jquery_script.type%20=%20%27text/javascript%27;head.appendChild(jquery_script);head.appendChild(jash_script);})();</span> </span></pre></div> </td></tr></table>
bookmarklet, interpreter, javascript, jquery

JavaScript

javascript if shorthand

var foo = (bar == 'harry') ? 'harry' : 'bob';
https://snipt.net/embed/e0b2847b7e8c7710486306cb49ef81d2/
/raw/e0b2847b7e8c7710486306cb49ef81d2/
e0b2847b7e8c7710486306cb49ef81d2
js
JavaScript
1
2019-06-06T21:34:47
True
False
False
/api/public/snipt/1697/
javascript-if-shorthand
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">foo</span> <span class="o">=</span> <span class="p">(</span><span class="nx">bar</span> <span class="o">==</span> <span class="s1">&#39;harry&#39;</span><span class="p">)</span> <span class="o">?</span> <span class="s1">&#39;harry&#39;</span> <span class="o">:</span> <span class="s1">&#39;bob&#39;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
javascript

JavaScript

to format epoch date using javascript

var thedate = Date(1224043200000);
alert(thedate);
https://snipt.net/embed/be7fa314e28fe360bed401208ce07c54/
/raw/be7fa314e28fe360bed401208ce07c54/
be7fa314e28fe360bed401208ce07c54
js
JavaScript
3
2019-06-17T09:44:27
True
False
False
/api/public/snipt/1656/
to-format-epoch-date-using-javascript
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">thedate</span> <span class="o">=</span> <span class="nb">Date</span><span class="p">(</span><span class="mi">1224043200000</span><span class="p">);</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">alert</span><span class="p">(</span><span class="nx">thedate</span><span class="p">);</span> </span></pre></div> </td></tr></table>
epcoh, javascript

JavaScript

demo

1
2
3
4
5
6
var m = function demo(a){
    return function(b){
       return a+b;
    }(4);
}(3);
alert(m);
https://snipt.net/embed/fe01ce2a7fbac8fafaed7c982a04e229/
/raw/fe01ce2a7fbac8fafaed7c982a04e229/
fe01ce2a7fbac8fafaed7c982a04e229
js
JavaScript
6
2019-06-12T21:36:39
True
False
False
/api/public/snipt/1378/
demo
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">m</span> <span class="o">=</span> <span class="kd">function</span> <span class="nx">demo</span><span class="p">(</span><span class="nx">a</span><span class="p">){</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">return</span> <span class="kd">function</span><span class="p">(</span><span class="nx">b</span><span class="p">){</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="nx">a</span><span class="o">+</span><span class="nx">b</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">}(</span><span class="mi">4</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}(</span><span class="mi">3</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="nx">alert</span><span class="p">(</span><span class="nx">m</span><span class="p">);</span> </span></pre></div> </td></tr></table>
javascript

JavaScript

fix for console.log

1
2
3
if (typeof console.log != function) {
    console.log = function(){ /* ... */ } 
}
https://snipt.net/embed/5dd678e5fdffd61bb86199d8992f31ea/
/raw/5dd678e5fdffd61bb86199d8992f31ea/
5dd678e5fdffd61bb86199d8992f31ea
js
JavaScript
3
2019-06-18T17:53:16
True
False
False
/api/public/snipt/1232/
fix-for-consolelog
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="o">!=</span> <span class="err">‘</span><span class="kd">function</span><span class="err">’</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span> <span class="cm">/* ... */</span> <span class="p">}</span> </span><span id="L-3"><a name="L-3"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
console.log, debug, firebug, javascript, js