I want to open 10 tabs of browsers from c# code, how could I do that?
protected void Page_Load(object sender, EventArgs e)
{
foreach (var url in Getdata())
{
string URL = string.Format("http://www.websitename.com/member_id={0}", url.Replace("Member", ""));
Response.Redirect(URL);
}
}
public List<string> Getdata()
{
List<string> Key = new List<string>();
Key.Add("Member2942048");
Key.Add("Member3271434");
Key.Add("Member3271124");
return Key;
}
Also suggest how to write jQuery / Javascript code for this (I could create arraylist in jQuery and read one by one)
This will do the job:
/// <summary>
/// Opens new window
/// </summary>
/// <param name="page"></param>
/// <param name="fullUrl"></param>
public static void OpenNewWindow(System.Web.UI.Page page, string fullUrl, string key)
{
string script = "window.open('" + fullUrl + "', '" + key + "', 'status=1,location=1,menubar=1,resizable=1,toolbar=1,scrollbars=1,titlebar=1');";
page.ClientScript.RegisterClientScriptBlock(page.GetType(), key, script, true);
}
From your current page you should call something like this:
OpenNewWindow(this,"http://someServer/somePage.aspx","key");
Make sure your page contains ScriptManager and key is uniqe on every call!
So in your code:
int i=0;
string key = "Opener";
foreach (var url in Getdata())
{
i +=1;
string URL = string.Format("http://www.websitename.com/member_id={0}", url.Replace("Member", ""));
OpenNewWindow(this,URL , key + i.ToString());
}
You cannot do this from server side code. what you can do is give the client a list of urls to open and then, let the client open new windows for each url. this could prove a little tricky since browsers my block you as windows spammer.
you can use Process.Start(websiteUrl );
Process BrowserProcess = new Process();
like this:
ProcessStartInfo psiOjbect = new ProcessStartInfo("http://DefaultWebsiteOfmyCompany.com"); // You can also use "about:blank".
BrowserProcess.StartInfo = psiOjbect;
BrowserProcess.Start();
Thread.Sleep(1000); //Need to wait
foreach (string websiteUrl in Properties.Settings.Default.WebSiteURLs)
{
Process.Start(websiteUrl );
}
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.