snipt

Ctrl+h for KB shortcuts

Text only

JavaScript iFrame Buster

1
2
3
4
5
6
7
/*
Oftentimes you want to make sure your site isn't being IFRAME'd.  Sometimes it's for security reasons, other times it's so your site's content isn't being skimmed else, and other times it's...oh, who cares, you just want to do it.  Here's a short way to escape frames:
*/

if (top.location != self.location) {
    top.location = self.location.href;
}
https://snipt.net/embed/ec92d1593c098837461fbc10ed5230fe/
/raw/ec92d1593c098837461fbc10ed5230fe/
ec92d1593c098837461fbc10ed5230fe
text
Text only
7
2019-08-15T11:50:32
True
False
False
Feb 18, 2014 at 10:11 AM
/api/public/snipt/114762/
javascript-iframe-buster
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>/* </span><span id="L-2"><a name="L-2"></a>Oftentimes you want to make sure your site isn&#39;t being IFRAME&#39;d. Sometimes it&#39;s for security reasons, other times it&#39;s so your site&#39;s content isn&#39;t being skimmed else, and other times it&#39;s...oh, who cares, you just want to do it. Here&#39;s a short way to escape frames: </span><span id="L-3"><a name="L-3"></a>*/ </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>if (top.location != self.location) { </span><span id="L-6"><a name="L-6"></a> top.location = self.location.href; </span><span id="L-7"><a name="L-7"></a>} </span></pre></div> </td></tr></table>
js

JavaScript

Prevenir que el JS se detenga por un browser que no soporta console

1
2
3
4
5
6
7
8
//Prevent undefined function
if(console=='undefined' || !console || console==null) {
    var console = {
        log : function (string) {
            
        }
    }
}
https://snipt.net/embed/437a60917d811a070afc0dfb6d79e6fe/
/raw/437a60917d811a070afc0dfb6d79e6fe/
437a60917d811a070afc0dfb6d79e6fe
js
JavaScript
8
2019-08-14T09:18:43
True
False
False
/api/public/snipt/61468/
prevenir-que-el-js-se-detenga-por-un-browser-que-no-soporta-console
<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="c1">//Prevent undefined function</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span><span class="p">(</span><span class="nx">console</span><span class="o">==</span><span class="s1">&#39;undefined&#39;</span> <span class="o">||</span> <span class="o">!</span><span class="nx">console</span> <span class="o">||</span> <span class="nx">console</span><span class="o">==</span><span class="kc">null</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">console</span> <span class="o">=</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">log</span> <span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">string</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> </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="p">}</span> </span></pre></div> </td></tr></table>
js

Text only

Ejecutar un PHP en vez de un JS

1
2
3
4
5
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/magic.js
RewriteCond %{QUERY_STRING} ((.*))?
RewriteRule (.*)  magic.php?%2 [L]
https://snipt.net/embed/47146a4e3fbda964500551cfd323c087/
/raw/47146a4e3fbda964500551cfd323c087/
47146a4e3fbda964500551cfd323c087
text
Text only
5
2019-08-13T16:19:19
True
False
False
/api/public/snipt/52883/
ejecutar-un-php-en-vez-de-un-js
<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>RewriteEngine on </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>RewriteCond %{REQUEST_URI} ^/magic.js </span><span id="L-4"><a name="L-4"></a>RewriteCond %{QUERY_STRING} ((.*))? </span><span id="L-5"><a name="L-5"></a>RewriteRule (.*) magic.php?%2 [L] </span></pre></div> </td></tr></table>
apache, htaccess, js, php, vhost