Jump to content

IE document Obj


Recommended Posts

Does the $oIE.document obj work just like the javascript doc obj? Also why is it when I use the AutoIt code the window title is prefixed with "http:// - "?

#NoTrayIcon
$oIE = ObjCreate("InternetExplorer.Application.1")
$EventObject = ObjEvent($oIE, "IEEvent_", "DWebBrowserEvents")

With $oIE
    .toolBar = False
    .left = (@DesktopWidth-600)/2
    .top = (@DesktopHeight-400)/2
    .width=600
    .height=400
    .visible = 1
    .navigate("about:blank")
    .document.write('<html><head><title>Test Page</title></head><body background="' & @Systemdir & '\oobe\images\mslogo.jpg"></body></html>')
    $IEWnd = HWnd(.hWnd)
EndWith

$x = 0
$y = 0
$width = 255
$height = 40
$document = $oIE.document
While WinExists($IEWnd)
    $x += 2
    $y += 1
    If $x >= $width Then $x -= $width
    If $y >= $height Then $y -= $height
    $document.title = $x & 'px ' & $y & 'px'
    $document.body.style.backgroundPosition = $x & 'px ' & $y & 'px'
    Sleep(50)
WEnd

Func OnAutoItExit()
    $EventObject.Stop
EndFunc

Func IEEvent_Quit($EventName)
    Exit
EndFunc

<html><head><title>Test Page</title></head>
<body background="C:\WINDOWS\system32\oobe\images\mslogo.jpg" onload="bgloop()">
<script type="text/javascript"><!--
var x = 0
var y = 0
var width = 255
var height = 40
function bgloop() {
x += 2
y += 1
if (x >= width) {x -= width}
if (y >= height) {y -= height}
document.title = x+'px '+y+'px'
document.body.style.backgroundPosition = x+'px '+y+'px'
mover = setTimeout("bgloop()", 50);
}
--></script></body></html>

Edit: Also for some reason, when I close the IE window, I get an AutoIt error about half the time. I'm guessing it's just not catching the Quit event fast enough.

Edited by gamerman2360
Link to comment
Share on other sites

AutoIt gives access to the browser Document Object Model (DOM) through COM. Javascript in the browser has latent access to the DOM. One difference between implementations is that the browser Javascript implementation assumes a root object of "window" and all references are implicitly relative to that root; AutoIt/COM makes no such assumption. Other than that, they both implement the DOM so are essentially equivalent.

Regarding capturing the quit method/event... AutoIt does not handle COM event delivery synchronously... events are queued to AutoIt and the source is told that the event is "handled" and is allowed to continue. So, there can easily be timing issues if you make synchronous assumptions.

Dale

Does the $oIE.document obj work just like the javascript doc obj? Also why is it when I use the AutoIt code the window title is prefixed with "http:// - "?

#NoTrayIcon
$oIE = ObjCreate("InternetExplorer.Application.1")
$EventObject = ObjEvent($oIE, "IEEvent_", "DWebBrowserEvents")

With $oIE
    .toolBar = False
    .left = (@DesktopWidth-600)/2
    .top = (@DesktopHeight-400)/2
    .width=600
    .height=400
    .visible = 1
    .navigate("about:blank")
    .document.write('<html><head><title>Test Page</title></head><body background="' & @Systemdir & '\oobe\images\mslogo.jpg"></body></html>')
    $IEWnd = HWnd(.hWnd)
EndWith

$x = 0
$y = 0
$width = 255
$height = 40
$document = $oIE.document
While WinExists($IEWnd)
    $x += 2
    $y += 1
    If $x >= $width Then $x -= $width
    If $y >= $height Then $y -= $height
    $document.title = $x & 'px ' & $yy & 'px'
    $document.body.style.backgroundPosition = $x & 'px ' & $yy & 'px'
    Sleep(50)
WEnd

Func OnAutoItExit()
    $EventObject.Stop
EndFunc

Func IEEvent_Quit($EventName)
    Exit
EndFunc
<html><head><title>Test Page</title></head>
<body background="C:\WINDOWS\system32\oobe\images\mslogo.jpg" onload="bgloop()">
<script type="text/javascript"><!--
var x = 0
var y = 0
var width = 255
var height = 40
function bgloop() {
x += 2
y += 1
if (x >= width) {x -= width}
if (y >= height) {y -= height}
document.title = x+'px '+yy+'px'
document.body.style.backgroundPosition = x+'px '+yy+'px'
mover = setTimeout("bgloop()", 50);
}
--></script></body></html>

Edit: Also for some reason, when I close the IE window, I get an AutoIt error about half the time. I'm guessing it's just not catching the Quit event fast enough.

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Would there be a way to stop the script to handle the event sooner, or something?

Not directly the way things are implemented today. You could experiment with a Sleep to idle out your script processing and allow the event queue to get processed, but there is not method of polling the event queue to insure that it is empty so there are no guarantees.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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