[removed] Overriding alert()

后端 未结 12 2100
忘了有多久
忘了有多久 2020-11-22 03:17

Has anyone got any experience with overriding the alert() function in JavaScript?

  • Which browsers support this?
  • Which browser-versions sup
12条回答
  •  误落风尘
    2020-11-22 03:54

    Ladislav.
    For IE8 you can redefine alert() like this way

    /** 
     * Definition of global attached to window properties 
    */ (function() { nalert = window.alert; Type = { native: 'native', custom: 'custom' }; })(); /** * Factory method for calling alert(). * It will be call a native alert() or a custom redefined alert() by a Type param. * This defeinition need for IE */ (function(proxy) { proxy.alert = function () { var message = (!arguments[0]) ? 'null': arguments[0]; var type = (!arguments[1]) ? '': arguments[1]; if(type && type == 'native') { nalert(message); } else { document.write('

    I am redefiend alert()
    Alert say: '+message+'

    '); } }; })(this);

    and call as

    alert('Hello, hacker!');
    nalert('I am native alert');
    alert('Hello, user!', Type.custom);
    

提交回复
热议问题