How can I close the newly opened Internet Explorer using the mshtml - microsoft.mshtml

I want to close a newly opened Internet Explorer using the mshtml.
I have a program , which takes values from different IE Window. The navigation to each Window is invoked using the Click() method of element. Once process the page, I want to close the Window.
Any one know how to close the window using the Mshtml.
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.
}

Easy: Get the HWND from IWebBrowser2, and send it a WM_CLOSE.

Related

How to close Microsoft Edge browser's new tab in c# code

How to run same page in browser, when I stopping and re running a page its displaying in new tab and i don't want to display in new tab and I want to display in same page and I'm working on windows form application in c# .net.
Can u please suggest me any one.
The below code I have written like this way.
Process.Start("microsoft-edge:http://www.google.com");
Process[] Edge = Process.GetProcessesByName("MicrosoftEdge");
foreach (Process Item in Edge)
{
try
{
Item.Kill();
Item.WaitForExit(100);
}
catch (Exception)
{
}
}.
Based on my research, I could not find a way to use Process to display the same page in the Edge.
However, I find a alternative method to do it.
First, please install nuget-package Selenium.WebDriver and Selenium.WebDriver.MSEdgeDriver.
Second, please copy the msedgedriver.exe from the packages (path:packages\Selenium.WebDriver.MSEdgeDriver.91.0.864.37\driver\win64)to the bin\debug folder and rename it to MicrosoftWebDriver.exe
Finally, you could try the following code to open the Google page to replace the Bing Page in the same tab:
var driver = new EdgeDriver();
// Navigate to Bing
driver.Url = "https://www.bing.com/";
driver.Navigate();
// Navigate to Google
driver.Url = "https://www.google.com/";
driver.Navigate();

Launching a webpage in browser from an Adobe Air app not working

I've got a webpage I want to hook in to my Adobe Air app. It's running JavaScript, so I can't open it in the app, but I'm trying to launch it in the default system browser.
Here's the code that's supposed to be launching the page:
public function beginModule():void {
var loader:HTMLLoader = new HTMLLoader();
var gameURL:URLRequest = new URLRequest("file:///path/to/file.html");
loader.navigateInSystemBrowser = true;
loader.load(gameURL);
}
I've also tried using
flash.net.navigateToURL(gameURL);
but that had no effect.
Every time I hit the above method, that block executes but nothing happens other than a quick cursor change-- no browser opened, no change in the app. What am I missing here?
Before you start, check if the HTML page is properly running in the browser.
To open a HTML page in flex, use the HTML tag: <mx:HTML></mx:HTML>
Something like this: https://snipt.net/anishnair/flex-show-html-page/?key=28838d54ac287180032dee000ce33a74
Thank you.
Regards,
Anish
Simply use :
navigateToURL(url,"_blank");
to navigate to the url in the web-browser.

Postback page minimized the browser - Selenium WebDriver

I have a web page that have few dropdowns and when the dropdown item changed it refresh the page and reloads.
so now i am writing script against that page and i have noticed that whenever my scripts select the text from the dropdown my browser get minimized.
my questions, is there any setting to make sure my browser is maximized while running the script?
Here is the code that SelectText from the dropdown:
public void SelectText(By locator, string txt)
{
IWebElement element = driver.FindElement(locator);
SelectElement selectelement = new SelectElement(element);
selectelement.SelectByText(txt);
}
I am using
IE 8
Selenium 2 WebDriver
C#
I strongly suspect that the browser is actually being dropped to the bottom of the Z-order, not minimized. That is to say, it's being pushed to the bottom of the stack of open windows on your desktop. If you have other applications running, and they're running maximized, it can appear as though IE has been minimized, but it really isn't. There are certain actions that are known to cause IE to behave this way, but no one has been able to figure out why yet.
Maximizing the IE window won't solve the problem. Nevertheless, you can maximize the IE window using
// WARNING! Untested code written from memory
// without the benefit of an IDE. Not guaranteed
// to be syntactically correct.
driver.Manage().Window.Maximize();

IE9 refresh after Ajax request returns

I have a JavaScript class that displays a partially-opaque div over top of the content of another div when an Ajax request is sent to the server.
When the request returns, the JavaScript class hides the partially-opaque div....it works great...sort of.
Right now, in IE9, when the Ajax request is complete, the partial-opacity is only hidden if the user moves their mouse.
So, my question is, how do I force the browser to do what it's supposed to do?
This is my extremely simple function that is called after the request returns to the browser:
_hideBlockingDiv: function() {
if (this.get_blockingDivClientID()) {
var blockingElement = $get(this.get_blockingDivClientID());
if (blockingElement != null) {
blockingElement.style.display = 'none';
//I know that this method is executing correctly because I "hi" showed
//up properly...but the element remained visible:
blockingElement.innerHTML = 'hi';
}
//if I add the alert then everything works fine in IE9
//if I don't then the page will remain the same until the user moves their mose
//alert("done");
}
}
Please note that I am not using JQuery.
I am using the AJAX.NET library since I am a .NET developer (and JQuery didn't become popular until years after I implemented my Ajax-enabled server controls)
Thanks
-Frinny
How and where do you call the _hideBlockingDiv function from? Since you are using MS Ajax library, you might want to have a page loaded handler on client side and call this function from within that handler. So basically
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function(){
_hideBlockingDiv();
});
Hope this helps!
It turns out that the problem only exists in the beta version of IE9 that I was using at the time. This problem went away once the full version of IE9 was released.

How do you bring a visible NativeWindow to the front of all applications in a Adobe AIR App

The application I'm working on is a HTML AIR application based on the AIR 2.5 SDK.
The application starts two windows: the first is a hidden window that registers it's self on the system tray (it's windows specific); the second is a visible lightweight window displaying showing various bits of information. Since the visible window is lightweight, there is no task bar entry to always the user bring the window to the front if hidden under other application windows.
The requirement is that on clicking the system tray icon the display window will be brought to the front.
My current solution looks something like:
function handleClick(){
var nativeDisplayWindow = findDisplayWindow();
nativeDisplayWindow.alwaysInFront = true;
nativeDisplayWindow.alwaysInFront = false;
}
function findDisplayWindow(){
// looks in air.NativeApplication.nativeApplication.openedWindows for the
// the display window and returns it
}
It works but really doesn't feel right.
I've tried using NativeWindow.orderToFront() & NativeWindow.activate() and various combinations of all the other method.
Is this the correct way to bring a window to the front of all application windows in AIR?
If you try casting your nativeDisplayWindow as a Window you should then be able to do something like:
function handleClick(){
var nativeDisplayWindow:Window = findDisplayWindow() as Window;
nativeDisplayWindow.orderToFront();
}
I don't know if this is what you are looking for or whether I've just repeated what you've explained?

Resources