I have the below code which opens a webpage when a user clicks on a Windows Form. The problem: When clickedagain while the webpage is open, the application opens another instance of the webpage and so on. How can I restrict the application not to open a second webpage when the first is active? (Like in javascript window.open("","myWindow","width=200,height=100");)) Any help is greatly appreciated.
My Code:
private void btLogin_Click(object sender, EventArgs e)
{
try
{
System.Diagnostics.Process.Start(MyLink);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
You can try the following code, Before opening the browser first we get the currently running browser processes(ex Chrome) and iterate through each process and compare the
MainWindowTitle
.This property holds the title of the opened browser window. If the target URL (with title) is already running then the rest of the code is ignored.