[英]Opening multiple tabs in a browser
I want to open 10 tabs of browsers from c# code, how could I do that? 我想从C#代码中打开10个浏览器选项卡,我该怎么做?
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) 还建议如何为此编写jQuery / Javascript代码(我可以在jQuery中创建arraylist并逐一读取)
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! 确保您的页面包含ScriptManager,并且每次调用的键都是唯一的!
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.
您可以做的是向客户端提供要打开的URL列表,然后让客户端为每个URL打开新窗口。 this could prove a little tricky since browsers my block you as windows spammer.
这可能会有些棘手,因为浏览器将我阻止为Windows垃圾邮件发送者。
you can use Process.Start(websiteUrl );
您可以使用
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 );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.