|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-01-11 16:58 UTC] csaba at alum dot mit dot edu
Description:
------------
If I do
$ie = new COM("InternetExplorer.Application");
$nav = "javascript:alert('hi mom');";
$ie->Navigate($nav);
IE vanishes, but fast
Note, this is run using PHP.exe (CLI) from a CMD box
on a Win XP Pro SP2 machine with IE 6
Thanks,
Csaba Gabor from Vienna
Reproduce code:
---------------
<?php
$ie = new COM("InternetExplorer.Application");
$ie->Visible = true;
$nav = "javascript:document.open();document.write('<body onload=\"alert(\\'Ready\\')\">Hi mom</body>');document.close();";
print "$nav\n";
sleep(3);
$ie->Navigate($nav);
sleep(5);
print "finished!\n";
?>
Expected result:
----------------
I expect to see a browser which displays a 'Ready' alert box and 'Hi Mom' in the browser window.
Actual result:
--------------
As soon as the $ie->Navigate is called, the bell clinks and IE is gone. The PHP program continues to run without error.
It doesn't seem to matter what is after the javascript:
It could be as simple as
$nav = "javascript:alert('hi mom');";
or you could get rid of the onload part from $nav in the example I supplied.
By the way, you can see that IE accepts $nav directly just fine (but get rid of the backslashes except one each before the inner single quotes, and of course remove the first " and the trailing "; - In other words, use what is printed to the CMD screen) by manually copying it in to the location bar and pressing enter yourself.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 12:00:01 2025 UTC |
I have tried this with the March 7 build and it is still not working in the same fashion, but I have a bit more information on it. It is tied to the fact that there is no previous navigation before the javascript:whatever is hit. For example, <?php $ie = new COM("InternetExplorer.Application"); //$nav = "javascript:'<body>Hi Mom</body>'"; $nav = "javascript:alert('Hi Mom')"; $ie->Visible = true; $ie->Navigate($nav); ?> will vanish IE, but <?php $ie = new COM("InternetExplorer.Application"); //$nav = "javascript:'<body>Hi Mom</body>'"; $nav = "javascript:alert('Hi Mom')"; $ie->Visible = true; $ie->Navigate("about:blank"); $ie->Navigate($nav); ?> will keep IE around (you can also use the non alert version). The point is that the 'pre navigation' to "about:blank" allows the main navigation to go through somehow.<?php $ie = new COM("InternetExplorer.Application"); $ie->Visible = true; $nav = "javascript:alert('hi mom');"; $ie->Navigate($nav); ?> Fair enough. I mean in the code above IE will vanish and not put up the alert. If, on the other hand, you put the following line into IE's address bar, IE will put up the expected alert and not vanish: javascript:alert('hi mom');I could only report an observed behaviour. Whether or not the problem lay with PHP is something I couldn't answer. But since entering the 'uri' manually worked, it was reasonable to report. For the record, here is the workaround I have found. You should add a single line, to navigate to about:blank before navigating to a javascript:protocol. The following will not crash IE: <?php $ie = new COM("InternetExplorer.Application"); $ie->Navigate("about:blank"); $ie->Visible = true; $nav = "javascript:alert('hi mom');"; $ie->Navigate($nav); ?>