首页 > 其他 > 详细

打开指定链接

时间:2020-07-26 00:29:15      阅读:127      评论:0      收藏:0      [点我收藏+]

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

打开指定链接

原文:https://www.cnblogs.com/skynight/p/13378771.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!