打开指定链接

2、比较灵活一点,可以定义窗口大小,我们要实现网页中脚本打开页面的方法,即window.open
那么,我们必然会想,如何调用页面的脚本呢?其实可以利用WebBrowser来实现

//连接

string url = "http://www.baidu.com" ;
//定义脚本
string script = @"<script language='javascript' type='text/javascript'>
    function openUrl(url){
    window.open(url,'测试窗口','width=400px,height=400px,directories=true,location=false,menubar=false,resizeable=false,scrollbars=yes,toolbar=false ');
    }</script>" ;
WebBrowser wb = new WebBrowser();
wb.DocumentText = @"<html> <head>" + script + "</head><body></body></html>" ; //定义WebBrowser中的DOM文档
wb.DocumentCompleted += delegate
{
  //执行脚本函数
  wb.Document.InvokeScript( "openUrl" , new object [] { url });
};
 
 private void button1_Click(object sender, EventArgs e)
        {
            //从注册表中读取默认浏览器可执行文件路径
            RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command\");
            string s = key.GetValue("").ToString();

            //s就是你的默认浏览器,不过后面带了参数,把它截去,不过需要注意的是:不同的浏览器后面的参数不一样!
            //"D:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -- "%1"
            System.Diagnostics.Process.Start(s.Substring(0, s.Length - 8), "http://blog.csdn.net/testcs_dn");
        }
https://www.cnblogs.com/glzgc/p/7940494.html

猜你喜欢

转载自www.cnblogs.com/skynight/p/13378771.html