Guest User

Untitled

a guest
Feb 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head></head>
  4.  
  5. <body>
  6.  
  7. <div id="txt_stage_1">_1_</div>
  8. <div id="txt_stage_2">_2_</div>
  9. <div id="txt_error">_no_error_</div>
  10.  
  11. <script>
  12.  
  13. function initExample() {
  14.  
  15. document.getElementById("txt_stage_1").innerText = "stage 1: passing?";
  16.  
  17. console.log("passed stage 1"); // works even if devtools are closed in Edge/IE11.
  18.  
  19. document.getElementById("txt_stage_1").innerText = "stage 1: passed: console.log: " + console.log;
  20.  
  21. try {
  22.  
  23. document.getElementById("txt_stage_2").innerText = "stage 2: passing?";
  24.  
  25. var x = console.log;
  26.  
  27. document.getElementById("txt_stage_2").innerText = "stage 2: passing? x: " + x;
  28. //var x = console.log.bind(this); // does not work, same TypeError.
  29.  
  30. x('passed stage 2'); // only works if devtools are open in Edge/IE11.
  31.  
  32. document.getElementById("txt_stage_2").innerText = "stage 2: passed: x: " + x;
  33.  
  34. } catch (e) {
  35.  
  36. // If devtools are not open a TypeError is thrown which hinders further execution
  37. // of the function that is calling that x(). So wrapping an anonymous function around x
  38. // will stop execution of the anonymous function, but the other code will continue to
  39. // work. If no wrapping function is provided then x is in the scope of the rest of the
  40. // module function and this script will stop execution when the TypeError is thrown.
  41.  
  42. document.getElementById("txt_error").innerText = "stage 3 error: " + e;
  43. }
  44. }
  45.  
  46. // IE11, closed devtools:
  47. // stage 1: passed: console.log:
  48. // function log() {
  49. // [native code]
  50. // }
  51. // stage 2: passing? x:
  52. // function log() {
  53. // [native code]
  54. // }
  55. // stage 3 error: TypeError: Ungültiges aufrufendes Objekt.
  56.  
  57. // IE11, open devtools:
  58. // stage 1: passed: console.log: function __BROWSERTOOLS_CONSOLE_SAFEFUNC(){try{return n(arguments)}catch(i){t(i)}}
  59. // stage 2: passed: x: function __BROWSERTOOLS_CONSOLE_SAFEFUNC(){try{return n(arguments)}catch(i){t(i)}}
  60. // _no_error_
  61.  
  62. // Edge, open devtools:
  63. // stage 1: passed: console.log: function __BROWSERTOOLS_CONSOLE_SAFEFUNC() { [native code] }
  64. // stage 2: passed: x: function __BROWSERTOOLS_CONSOLE_SAFEFUNC() { [native code] }
  65. // _no_error_
  66.  
  67. // Edge, closed devtools:
  68. // stage 1: passed: console.log: function log() { [native code] }
  69. // stage 2: passing? x: function log() { [native code] }
  70. // stage 3 error: TypeError: Ungültiges aufrufendes Objekt.
  71.  
  72. window.onload = initExample;
  73.  
  74. </script>
  75.  
  76. </body>
  77.  
  78. </html>
Add Comment
Please, Sign In to add comment