|
Posted by Csaba Gabor on 12/21/05 14:50
A sad day. For PHP readers, the complete thread is found here:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/60438965c65c574b/
I was able to implement the PHP event handler for the
InternetExplorer.Application object by going through the
MSScriptControl.ScriptControl, for which I show the code below. This
code requires the IEevents.ocx which I described in the previous post.
This works fine as long as I use a php.exe, php-win.exe, or even
php-cgi.exe (collectively referred to as CLI) from the command line (on
my Win XP Pro system) to invoke Launcher.php.
Unfortunately, it breaks right away (line 2) when I invoke it as a
result of a web request: IE.EventHandler cannot be created. Thus, the
technique I show is not useful here because, as I have mentioned in my
first post, it is possible to directly connect up
InternetExplorer.Application events to PHP code (using com_event_sink),
when PHP is run as CLI.
Nevertheless, this technique has wide applicability to DOM event
handling without any .ocx requirement.
Sigh,
Csaba Gabor from Vienna
Launcher.php (requires IEevents.ocx for the creation of IE.EventHandler
- see previous post):
<?php
$ieHandler = new COM("IE.EventHandler");
$IE = $ieHandler->newIE;
$IE->Visible = true;
$oClassInstance = new evtHandler; // PHP event handler
$oClassInstance->IE = $IE; // create local var for said handler
// set up the event handler connection
$oScript = new COM("MSScriptControl.ScriptControl");
$oScript->Language = "VBScript";
$oScript->AddObject ("scriptClassInstRef", $oClassInstance);
$oScript->AddObject ("ieHandler", $ieHandler);
// next 4 lines connect the VBScript handler to PHP handler
$oScript->AddCode('Sub EvtWrapper()
scriptClassInstRef.dispatchEvent _
"DownloadCompleteHandler", "Download Complete"
End Sub');
// next line connects the OCX handler to the VBScript handler
$oScript->ExecuteStatement ('ieHandler.setHandler
GetRef("EvtWrapper")');
$IE->Navigate2 ("http://www.google.com");
try { while ($IE->visible) com_message_pump(600); }
catch (Exception $e) { popup ("IE has gone away"); }
popup ("Done with PHP Script");
$webP = !!$_SERVER['REQUEST_METHOD']; // request from the web?
if ($webP)
print "<html><head><title>Events demo</title></head>
<body>IE has loaded its document,
DownloadComplete was detected,
and IE was terminated</body></html>";
class evtHandler {
function DownloadCompleteHandler() {
$aArgs = func_get_args();
if ($this->IE->ReadyState>=2) {
popup ($this->IE->LocationURL,
$aArgs[0] . " - " . $this->IE->ReadyState);
$this->IE->Quit(); } }
public $dispatchEvent;
function dispatchEvent() { call_user_func_array (array(&$this,
"".array_shift($argsRest=func_get_args())), $argsRest); }
}
function popup ($text, $title="PHP popup", $timeout=4, $style=131120) {
$oWSH = new COM("WScript.Shell");
if (is_null($text)) $text = "NULL";
$oWSH->Popup($text, $timeout, $title, $style); }
?>
[Back to original message]
|