I have a piece of JavaScript (run from Windows Scripting Host) which creates an IE window with some HTML in it. There are also a few JavaScript methods defined in the HEAD of the HTML document. What I want to do is call the methods in the HEAD block from the JavaScript which created the HTML document. I can't figure out how to do it. Any ideas?
Here is a simple example of what I'm trying to accomplish:
var oIE = WScript.CreateObject("InternetExplorer.Application");
oIE.navigate("about:blank");
var doc1 = oIE.Document;
oIE.visible = 1;
doc1.open();
doc1.writeln("<HTML>");
doc1.writeln("<HEAD>");
doc1.writeln("<script id=\"myscr\" language=\"JavaScript1.2\">");
doc1.writeln("function foobar() {");
doc1.writeln(" alert(\"foobar\")");
doc1.writeln("}");
doc1.writeln("</SCRIPT>");
doc1.writeln("</HEAD>");
doc1.writeln("<BODY>");
doc1.writeln("This is some body text.");
doc1.writeln("</BODY>");
doc1.writeln("</HTML>");
doc1.close();
// do something here to call the foobar() method within the IE window
.
This script, when run from Windows Scripting Host, creates the IE window which contains a JavaScript function foobar() inside it. I want to call that foobar() method from the above script, *not* by clicking a button in IE or anything like that.
Ideas?