Jump to content

Recommended Posts

Posted (edited)
#include <IE.au3>
#include <Array.au3>

Local $oIE = _IECreate()
Local $ss = ""
$ss &= 'var fruits = new Array();'
$ss &= 'fruits[0] = "pear";'
$ss &= 'fruits[1] = "peach";'
$ss &= 'fruits[2] = "pineapple";'
$ss &= 'fruits[3] = "strawberry";'
$ss &= 'return fruits;'

;Local $aa = $oIE.document.parentwindow.execScript($ss)
Local $aa = $oIE.document.parentwindow.eval($ss)

If IsArray($aa) Then
    _ArrayDisplay($aa, '$aa')
EndIf

_IEQuit($oIE)

error occurred:

Local $aa = $oIE.document.parentwindow.eval($ss)
Local $aa = $oIE.document.parentwindow^ ERROR

As above

if want to get the value of the variable 'fruits' in the statement

How does it work?

thanks!

Edited by Letraindusoir
Posted

Eval is not working anymore with ObjCreate("InternetExplorer.Application").  Here's another way :

#include <Constants.au3>
#include <IE.au3>
#include <Array.au3>

Example2()

Func Example2 ()
  Local $hGUI = GUICreate("Browser", @DesktopWidth / 2, @DesktopHeight / 2)
  ;GUISetState() ;Show GUI

  Global $oIE = ObjCreate("Shell.Explorer.2")
  $hIE = GUICtrlCreateObj($oIE, 0, 0, @DesktopWidth / 2, @DesktopHeight / 2)
  $oIE.navigate('about:blank')
  $arr = StringSplit($oIE.Document.parentWindow.eval('function tt() {var fruits = [];fruits[0] = "pear";fruits[1] = "peach";' & _
    'fruits[2] = "pineapple";fruits[3] = "strawberry"; return fruits[0]+"|"+fruits[1]+"|"+fruits[2]+"|"+fruits[3];}; tt();'), "|", $STR_NOCOUNT)
  _ArrayDisplay($arr)
EndFunc

 

Posted
6 minutes ago, Nine said:

Eval is not working anymore with ObjCreate("InternetExplorer.Application").  Here's another way :

#include <Constants.au3>
#include <IE.au3>
#include <Array.au3>

Example2()

Func Example2 ()
  Local $hGUI = GUICreate("Browser", @DesktopWidth / 2, @DesktopHeight / 2)
  ;GUISetState() ;Show GUI

  Global $oIE = ObjCreate("Shell.Explorer.2")
  $hIE = GUICtrlCreateObj($oIE, 0, 0, @DesktopWidth / 2, @DesktopHeight / 2)
  $oIE.navigate('about:blank')
  $arr = StringSplit($oIE.Document.parentWindow.eval('function tt() {var fruits = [];fruits[0] = "pear";fruits[1] = "peach";' & _
    'fruits[2] = "pineapple";fruits[3] = "strawberry"; return fruits[0]+"|"+fruits[1]+"|"+fruits[2]+"|"+fruits[3];}; tt();'), "|", $STR_NOCOUNT)
  _ArrayDisplay($arr)
EndFunc

 

Thanks!

But Still Report Error:

$arr = StringSplit($oIE.Document.parentWindow^ ERROR

Windows 7 + IE11

Is it related to the system and browser?

Posted

It is working for me on Win7.  You may need to set FEATURE_BROWSER_EMULATION in the registry for AutoIt3.exe to "0x2AF9". 

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

Posted
#include <Constants.au3>
#include <IE.au3>
#include <Array.au3>

Example2()

Func Example2 ()
  Local $hGUI = GUICreate("Browser", @DesktopWidth / 2, @DesktopHeight / 2)
  ;GUISetState() ;Show GUI

  Global $oIE = ObjCreate("Shell.Explorer.2")
  $hIE = GUICtrlCreateObj($oIE, 0, 0, @DesktopWidth / 2, @DesktopHeight / 2)
  $oIE.navigate('about:blank')
  $arr = $oIE.Document.parentWindow.eval('alert(123)')
EndFunc

After simplified

tests are still 'execScript no-error-reporting' and 'eval error-reporting'

Posted

IDK.  Since it works for me.  Try different value of emulation ?

; IE11 edge mode: 11001 (0x2AF9)
; IE11: 11000 (0x2AF8)
; IE10: 10001 (0x2711)
; IE10: 10000 (0x02710)
; IE 9: 9999 (0x270F)
; IE 9: 9000 (0x2328)
; IE 8: 8888 (0x22B8)
; IE 8: 8000 (0x1F40)
; IE 7: 7000 (0x1B58)

 

Posted
9 minutes ago, Nine said:

It is working for me on Win7.  You may need to set FEATURE_BROWSER_EMULATION in the registry for AutoIt3.exe to "0x2AF9". 

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

I think There is something wrong with the grammar of javascript sentences

I have used 'eval' or 'execScript' before, that sometimes work  sometimes don't work

Posted
var fruits = new Array();
fruits[0] = "pear";
fruits[1] = "peach";
fruits[2] = "pineapple";
fruits[3] = "strawberry";
console.log(fruits)

The above statement runs on the browser console without error
Not with eval or execScript.
It seems that this is also a puzzling problem

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...