HTML
<script type="text/javascript"> test = "hello"; </script>
<?php mb_internal_encoding('UTF-8'); mb_http_output('CP932'); ob_start('mb_output_handler'); $ie = new COM('InternetExplorer.Application', null, CP_UTF8); $ie->Navigate("http://syoboi.jp/"); $ie->Visible = true; while ($ie->ReadyState != 4 || $ie->Busy) { echo "待ち\n"; sleep(1); } echo $ie->Document->Script->test, "\n";
これで今まではうまく動いていた。結果はこう。変数testに設定した"hello"を表示できた。
C:\test> php ietest.php 待ち hello
それがIE9にすると、エラーが起こるようになった。
PHP Fatal error: Uncaught exception 'com_exception' with message 'Unable to lookup `test': 名前が不明です。 ' in C:\test\ietest.php:16 Stack trace: #0 C:\test\ietest.php(16): unknown() #1 {main} thrown in C:\test\ietest.php on line 16
IE9 が標準モードだと動かないみたいで、ページ側で互換モードを指定してやれば今まで通りうごく。
同じようなのをJScriptで書いてみたら、こっちは標準モードでもちゃんとうごく...。
var ie = new ActiveXObject("InternetExplorer.Application"); ie.visible = true; ie.navigate("http://syoboi.jp/"); while (ie.ReadyState != 4 || ie.Busy) { WScript.StdOut.WriteLine("待ち"); WScript.Sleep(1000); } WScript.StdOut.WriteLine(ie.Document.Script.test);