Advertisement
Noseratio

Injecting code into a child frame v2

Aug 24th, 2013
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- http://stackoverflow.com/questions/18342200/how-do-i-call-eval-in-ie-from-c/ -->
  2. <head>
  3. <script>
  4. function Test()
  5. {
  6.     var ie = new ActiveXObject("InternetExplorer.Application");
  7.     ie.Visible = true;
  8.     ie.Navigate("http://jsfiddle.net/");
  9.    
  10.     WhenLoaded(ie, function() {
  11.         // injector code
  12.         var __execScript = "(window.__execScript = function(exp) { return eval(exp); }, window.self)";
  13.  
  14.         // inject into main window
  15.         ie.Document.parentWindow.eval(__execScript);
  16.         ie.Document.parentWindow.__execScript('alert(document.URL)');
  17.  
  18.         // inject into a child frame - from the context of the main window
  19.             var iframe = ie.Document.parentWindow.__execScript('document.all.tags("iframe")[0].contentWindow.eval("' + __execScript + '")');
  20.         iframe.__execScript('alert(document.URL)');
  21.     });
  22.  
  23. }
  24.  
  25. function WhenLoaded(ie, loaded)
  26. {
  27.     if (ie.readyState === 4)
  28.         loaded();
  29.     else
  30.         setTimeout(function() { WhenLoaded(ie, loaded); }, 250);
  31. }
  32. </script>
  33. </head>
  34.  
  35. <body>
  36. <button onclick="Test()">Test</button>
  37. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement