Skip to content

Instantly share code, notes, and snippets.

@azproduction
Created April 11, 2014 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azproduction/10469755 to your computer and use it in GitHub Desktop.
Save azproduction/10469755 to your computer and use it in GitHub Desktop.
Deleted prototype element or function
var encodeURIComponent, Array_push, Number_toString;
(function() {
    var iframe = document.createElement('iframe'), loaded = false;
    iframe.style.width = '1px';
    iframe.style.height = '1px';
    iframe.style.position = 'absolute';
    var onloadIframe = function() {
        if (!loaded && iframe.contentWindow) {
            loaded = true;
            // Без onload в IE не создаётся JavaScript-окружение
            iframe.contentWindow.document.write('<body onload=""></body>');
            iframe.contentWindow.document.close();

            var thatWindow = iframe.contentWindow;
            encodeURIComponent = thatWindow.encodeURIComponent;
            Array_push = thatWindow.Array.prototype.push;
            Number_toString = thatWindow.Number.prototype.toString;

            document.documentElement.removeChild(iframe);
            setTimeout(function() {
                // Без этого таймера IE удаляет выдернутые функции, в результате чего они становятся
                // какими-то объектами.
            }, 3600 * 24 * 1000);
        }
    };
    iframe.onload = onloadIframe;
    document.documentElement.insertBefore(iframe, document.documentElement.firstChild);
    onloadIframe();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment