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.

7
  • That would be IHTMLDocument::get_Script, I believe. You would need to call eval via late binding. Commented Sep 24, 2014 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. Commented Sep 24, 2014 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. Commented Sep 24, 2014 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' Commented Sep 24, 2014 at 20:42
  • 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. Commented Sep 25, 2014 at 2:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.