Article ID: 252030
Article Last Modified on 6/14/2006
APPLIES TO
- Microsoft Java Virtual Machine
This article was previously published under Q252030
SUMMARY
This article describes how to invoke Microsoft Internet Explorer from Java and navigate to a URL.
MORE INFORMATION
Steps to Invoke Internet Explorer
- In Microsoft Visual J++ 6.0, create a new empty project.
- Add a new class to the project named Navigate.java.
Paste the following code into the file:
import com.ms.com.*; import shdocvw.*; public class Navigate { IWebBrowserApp testBrowser = null; public static void main( String args[] ) { IWebBrowser2 testBrowser = (IWebBrowser2)new InternetExplorer(); testBrowser.getApplication(); testBrowser.setVisible(true); Variant var = new Variant(); var.putEmpty(); testBrowser.Navigate("http://www.msdn.microsoft.com",var,var, var, var); } }
- Click Project, and then click Add COM Wrapper to add the Component Object Model (COM) wrappers for the Microsoft Internet Controls (Shdocvw.dll).
- Compile and test the new project.
NOTE: The IWebBrowser2 interface replaces the IWebBrowserApp and IWebBrowser interfaces.
NOTE: In this example, the last four parameters of the Navigate method are optional. As a result, we create a Variant and call its putEmpty() method to act as the arguments that we are not supplying.
REFERENCES
For information about the IWebBrowser2 interface, see the following article on the Microsoft Developer Network (MSDN):
http://msdn.microsoft.com/workshop/browser/webbrowser/reference/IFaces/IWebBrowser2/IWebBrowser2.asp
For information about the IWebBrowser2::Navigate method, see the following MSDN article:
For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:
Keywords: kbhowto kbjava KB252030