Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head></head>
- <body>
- <div id="txt_stage_1">_1_</div>
- <div id="txt_stage_2">_2_</div>
- <div id="txt_error">_no_error_</div>
- <script>
- function initExample() {
- document.getElementById("txt_stage_1").innerText = "stage 1: passing?";
- console.log("passed stage 1"); // works even if devtools are closed in Edge/IE11.
- document.getElementById("txt_stage_1").innerText = "stage 1: passed: console.log: " + console.log;
- try {
- document.getElementById("txt_stage_2").innerText = "stage 2: passing?";
- var x = console.log;
- document.getElementById("txt_stage_2").innerText = "stage 2: passing? x: " + x;
- //var x = console.log.bind(this); // does not work, same TypeError.
- x('passed stage 2'); // only works if devtools are open in Edge/IE11.
- document.getElementById("txt_stage_2").innerText = "stage 2: passed: x: " + x;
- } catch (e) {
- // If devtools are not open a TypeError is thrown which hinders further execution
- // of the function that is calling that x(). So wrapping an anonymous function around x
- // will stop execution of the anonymous function, but the other code will continue to
- // work. If no wrapping function is provided then x is in the scope of the rest of the
- // module function and this script will stop execution when the TypeError is thrown.
- document.getElementById("txt_error").innerText = "stage 3 error: " + e;
- }
- }
- // IE11, closed devtools:
- // stage 1: passed: console.log:
- // function log() {
- // [native code]
- // }
- // stage 2: passing? x:
- // function log() {
- // [native code]
- // }
- // stage 3 error: TypeError: Ungültiges aufrufendes Objekt.
- // IE11, open devtools:
- // stage 1: passed: console.log: function __BROWSERTOOLS_CONSOLE_SAFEFUNC(){try{return n(arguments)}catch(i){t(i)}}
- // stage 2: passed: x: function __BROWSERTOOLS_CONSOLE_SAFEFUNC(){try{return n(arguments)}catch(i){t(i)}}
- // _no_error_
- // Edge, open devtools:
- // stage 1: passed: console.log: function __BROWSERTOOLS_CONSOLE_SAFEFUNC() { [native code] }
- // stage 2: passed: x: function __BROWSERTOOLS_CONSOLE_SAFEFUNC() { [native code] }
- // _no_error_
- // Edge, closed devtools:
- // stage 1: passed: console.log: function log() { [native code] }
- // stage 2: passing? x: function log() { [native code] }
- // stage 3 error: TypeError: Ungültiges aufrufendes Objekt.
- window.onload = initExample;
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment