简体   繁体   中英

How can I close the newly opened Internet Explorer using the mshtml (c# code)

I want to close a newly opened internet Explorer window using the mshtml (c# code). I used the Mshtml with the instance of Ie and navigated through a url and clicked on a link. Once i click the link, i am getting the document opened in a new window. I want to know is there any way to fetch the values from the newly opened window and after getting the values to close the window..

Thanks in advance....

Unni

See the following code...

using System.Runtime.InteropServices;
// IE can be found in COM library called 
// Microsoft Internet Controls: 
using IE = SHDocVw.InternetExplorer; 
static void OpenAndCloseIE()
{
    // Get an instance of Internet Explorer: 
    Type objClassType = Type.GetTypeFromProgID("InternetExplorer.Application");
    var instance = Activator.CreateInstance(objClassType) as IE;

    // Close Internet Explorer again: 
    instance.Quit();

    // Release instance: 
    System.Runtime.InteropServices.Marshal.ReleaseComObject(instance);
    instance = null; // Don't forget to unreference it. 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM