C#怎么实现从浏览器获取当前访问网页的URL
时间:2011-12-11
来源:互联网
我用C#winform写了一个小程序,想从浏览器上获得当前访问网页的URL。我的方法是:
[code=C#][/code]ShellWindows shellwindows = new ShellWindows();
foreach (InternetExplorer ie in shellwindows)
{
string filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore"))
{
if (txt_ReceiveUrl .Text !=ie.LocationURL .ToString ())
{
txt_ReceiveUrl.Text = ie.LocationURL.ToString();
txt_pageTitle.Text = ie.FullName.ToString();
}
}
}
这种方只能从系统自带的IE浏览器上获得URL,但是,无法从其他浏览器上获得URL,我试了 搜狗浏览器、遨游浏览器,都无法从上面获得URL。请问各位大侠,我怎么才能其它的浏览器上获得当前访问网页的URL呢?
[code=C#][/code]ShellWindows shellwindows = new ShellWindows();
foreach (InternetExplorer ie in shellwindows)
{
string filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore"))
{
if (txt_ReceiveUrl .Text !=ie.LocationURL .ToString ())
{
txt_ReceiveUrl.Text = ie.LocationURL.ToString();
txt_pageTitle.Text = ie.FullName.ToString();
}
}
}
这种方只能从系统自带的IE浏览器上获得URL,但是,无法从其他浏览器上获得URL,我试了 搜狗浏览器、遨游浏览器,都无法从上面获得URL。请问各位大侠,我怎么才能其它的浏览器上获得当前访问网页的URL呢?
作者: monkin2011 发布时间: 2011-12-11
using System;
using System.Windows.Forms;
using SHDocVw;
namespace WindowsApplication35
... {
public partial class Form1 : Form
... {
public Form1()
... {
InitializeComponent();
}
private void Form1_Load( object sender, EventArgs e)
... {
ShellWindowsClass shellWindows = new ShellWindowsClass();
foreach (InternetExplorer ie in shellWindows)
... {
string filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals( " iexplore " ))
... {
Console.WriteLine(ie.LocationURL);
}
}
}
}
}
webBrowser1.Document.window.loaction.href;
利用的是webBrowser对象的属性,索引到页面的window对象而读取的当前页面的链接地址,进行读取.
或许这并不是个好方法。
具体的内容,可以查看这个对象的属性方法.
webBrowser1.DocumentText;
是整个页面的源文件.
你可以使用浏览器的api来获取
using System.Windows.Forms;
using SHDocVw;
namespace WindowsApplication35
... {
public partial class Form1 : Form
... {
public Form1()
... {
InitializeComponent();
}
private void Form1_Load( object sender, EventArgs e)
... {
ShellWindowsClass shellWindows = new ShellWindowsClass();
foreach (InternetExplorer ie in shellWindows)
... {
string filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals( " iexplore " ))
... {
Console.WriteLine(ie.LocationURL);
}
}
}
}
}
webBrowser1.Document.window.loaction.href;
利用的是webBrowser对象的属性,索引到页面的window对象而读取的当前页面的链接地址,进行读取.
或许这并不是个好方法。
具体的内容,可以查看这个对象的属性方法.
webBrowser1.DocumentText;
是整个页面的源文件.
你可以使用浏览器的api来获取
作者: hefeng_aspnet 发布时间: 2011-12-11
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28