snipt

Ctrl+h for KB shortcuts

HTML

jQuery - Detect browser tab close

1
2
3
4
5
<script type="text/javascript">
    window.onbeforeunload = function () {
        return "Do you really want to close?";
    };
</script>
https://snipt.net/embed/1f7e00666842076d0380b2bbe01d2d52/
https://snipt.net/raw/1f7e00666842076d0380b2bbe01d2d52/
1f7e00666842076d0380b2bbe01d2d52
html
HTML
5
2016-05-27T02:25:25
True
False
False
May 26, 2016 at 06:17 AM
/api/public/snipt/147054/
jquery-detect-browser-tab-close
<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="nt">&lt;script </span><span class="na">type=</span><span class="s">&quot;text/javascript&quot;</span><span class="nt">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="nb">window</span><span class="p">.</span><span class="nx">onbeforeunload</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="s2">&quot;Do you really want to close?&quot;</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">};</span> </span><span id="L-5"><a name="L-5"></a><span class="nt">&lt;/script&gt;</span> </span></pre></div> </td></tr></table>

Text only

Default Timestamp

 `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
https://snipt.net/embed/f99dbed8067d0e301a66b517e6eac47a/
https://snipt.net/raw/f99dbed8067d0e301a66b517e6eac47a/
f99dbed8067d0e301a66b517e6eac47a
text
Text only
1
2016-05-27T02:25:30
True
False
False
May 25, 2016 at 04:41 PM
/api/public/snipt/147048/
default-timestamp
<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 id="L-1"><a name="L-1"></a> `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP </span></pre></div> </td></tr></table>
mysqli

PHP

Generate random hex color

1
2
3
4
5
<?php

$color = '#'.str_pad(dechex(rand(0,255)), 2, 0).str_pad(dechex(rand(0,255)), 2, 0).str_pad(dechex(rand(0,255)), 2, 0);

?>
https://snipt.net/embed/6cf0e2b075edfb2514c35c15e9f17dc4/
https://snipt.net/raw/6cf0e2b075edfb2514c35c15e9f17dc4/
6cf0e2b075edfb2514c35c15e9f17dc4
php
PHP
5
2016-05-27T02:25:31
True
False
False
/api/public/snipt/147047/
generate-random-hex-color
<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="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nv">$color</span> <span class="o">=</span> <span class="s1">&#39;#&#39;</span><span class="o">.</span><span class="nb">str_pad</span><span class="p">(</span><span class="nb">dechex</span><span class="p">(</span><span class="nb">rand</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">255</span><span class="p">)),</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="nb">str_pad</span><span class="p">(</span><span class="nb">dechex</span><span class="p">(</span><span class="nb">rand</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">255</span><span class="p">)),</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="nb">str_pad</span><span class="p">(</span><span class="nb">dechex</span><span class="p">(</span><span class="nb">rand</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">255</span><span class="p">)),</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</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="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
color, hex, php

JavaScript

js

1
2
3
4
5
var example_array = ['apple', 'pear', 'bannana'];
var num_fruits = example_array.length;

var example_number = 1;
var example_text = "Crystal";
https://snipt.net/embed/dbad603e51ba15b604631939378a156c/
https://snipt.net/raw/dbad603e51ba15b604631939378a156c/
dbad603e51ba15b604631939378a156c
js
JavaScript
6
2016-05-27T02:25:32
True
False
False
May 25, 2016 at 07:56 AM
/api/public/snipt/147043/
js-625bd3ec
<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="kd">var</span> <span class="nx">example_array</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;apple&#39;</span><span class="p">,</span> <span class="s1">&#39;pear&#39;</span><span class="p">,</span> <span class="s1">&#39;bannana&#39;</span><span class="p">];</span> </span><span id="L-2"><a name="L-2"></a><span class="kd">var</span> <span class="nx">num_fruits</span> <span class="o">=</span> <span class="nx">example_array</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="kd">var</span> <span class="nx">example_number</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="kd">var</span> <span class="nx">example_text</span> <span class="o">=</span> <span class="s2">&quot;Crystal&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.