iFrame or not?
April 7th, 2011
No comments
How to detect if our website is opened inside an iFrame?
if ( window != window.top ) { alert("I'm in a frame!"); }
Categories: JavaScript
How to detect if our website is opened inside an iFrame?
if ( window != window.top ) { alert("I'm in a frame!"); }
При опит да поставим Google Analytics tracking pixel чрез редакция на template в админа се получава следната грешка:
Parse error: syntax error, unexpected '[' in /var/www/vhosts/path/to/includes/adminfunctions_template.php(4667) : eval()'d code on line 133
За да избегнем това, заграждаме GA кода следният таг < vb:literal >
<vb:literal> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-ХХХХХХХХ-У']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </vb:literal>
Посочените по-долу тестове са написани от Dmitry Baranovskiy в неговия блог под заглавието “So, you think you know JavaScript?“. Интересни са и затова ги copy/paste-вам тук.
Можете ли да отговорите какво ще върне всеки alert() докато четете кода, без да го тествате?
if (!("a" in window)) { var a = 1; } alert(a);
var a = 1, b = function a(x) { x && a(--x); }; alert(a);
function a(x) { return x * 2; } var a; alert(a);
function b(x, y, a) { arguments[2] = 10; alert(a); } b(1, 2, 3);
function a() { alert(this); } a.call(null);