1

Looking at Compatibility changes in IE11, we have that window.execScript is replaced with eval. Now when using the IE COM object how can we get hold of the JavaScript Global Object that has the eval function?

PowerShell:

$ie = New-Object -COM InternetExplorer.Application
$document = $ie.document
$window = $document.parentWindow
# How to get JavaScript Global Object from these?

See also this related question.

Community
  • 1
  • 1
orad
  • 15,272
  • 23
  • 77
  • 113
  • That would be [`IHTMLDocument::get_Script`](http://msdn.microsoft.com/en-us/library/aa752642.aspx), I believe. You would need to call `eval` via late binding. – Igor Tandetnik Sep 24 '14 at 19:31
  • I can't find any properties in `$ie.Document.Script` that points to the JavaScript Global Object. Do you have an example of using it using PowerShell or WSH? Thanks. – orad Sep 24 '14 at 20:08
  • What do you mean, points to? The `IDispatch*` that `IHTMLDocument::get_Script` returns **is** the global object. I'm not familiar with PowerShell. In WSH, just simply `ie.Document.Script.eval('alert("Hi")')` should work. – Igor Tandetnik Sep 24 '14 at 20:15
  • Running `$ie.Document.Script.eval('alert("Hi")')` I get this error: Method invocation failed because [System.__ComObject] does not contain a method named 'eval' – orad Sep 24 '14 at 20:42
  • Apparently, for late binding in PowerShell, you need to do something like [this](http://blogs.technet.com/b/heyscriptingguy/archive/2010/12/14/dynamic-method-invocation-in-powershell.aspx) (but recall that I don't really know what I'm talking about). WHS runs JavaScript or VBScript, which use late binding natively. – Igor Tandetnik Sep 24 '14 at 20:48
  • 2
    OK, so the article says we can do this: `$window."alert".Invoke("Hi")` or this `$ie.document.Script."alert".Invoke("Hi")` which works! In case of `eval`, however, this doesn't work: `$ie.document.Script."eval".Invoke('alert("Hi")')` Error: You cannot call a method on a null-valued expression. – orad Sep 25 '14 at 02:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/61866/discussion-between-orad-and-igor-tandetnik). – orad Sep 25 '14 at 02:36

0 Answers0