c# webbrowser问题
<div class="lFloat icon hand" onclick="turnSas('http://www.163.com')">
function turnSas(url)
{
window.open(url);
}
我想在webbrowser_NewWindow 里获取到turnSas里的地址应该怎么做呢?
webbrowser.StatusText 这个方法不行 --------------------编程问答-------------------- 这个要先声明 然后再调 用JS
第一步:
/*调用JS类前声明*/
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
第二步:
webbrowser.Document.InvokeScript("turnSas");//调用页面JS --------------------编程问答-------------------- 这个不行吗?
--------------------编程问答--------------------
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.StatusTextChanged += webBrowser1_StatusTextChanged;
}
void webBrowser1_StatusTextChanged(object sender, EventArgs e)
{
MessageBox.Show(webBrowser1.StatusText);
}
namespace GetSessionkey
{
/*调用JS类前声明*/
//[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
//[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class FrmGetSessionKey : FormAll
{
public FrmGetSessionKey()
{
InitializeComponent();
}
private void Btn_First_Click(object sender, EventArgs e)
{
wbGetSessionkey.Document.InvokeScript("doclick");//调用页面JS
}
}
}
这个是我的代码 删减版 --------------------编程问答-------------------- 你那代码。。。
我不知道那个可以运行呢。。。。 --------------------编程问答--------------------
谢谢,我想取出turnSas里的地址来。 --------------------编程问答-------------------- 你点链接调转后就是turnSas地址了 --------------------编程问答-------------------- 那个啊,不能这么搞,必须循环里面的元素,
然后把字符串截出来,
这东西一点都不让人喜欢,
哥我前阵子刚搞过,怪不爽的 --------------------编程问答-------------------- 对 要不然你就先在代码里点这个链接
然后在webBrowser1_DocumentCompleted事件里判断,
再把这个URL给取出来 --------------------编程问答-------------------- 是不是要做爬虫抓取地址啊,
如果是那样就没必要用这东东了,
取出页面内容,搞个正则,匹配一下就出来了 --------------------编程问答--------------------
一点链接就弹出IE来了 --------------------编程问答--------------------
那没有办法 了
你就这样做吧
HtmlElementCollection hec = wbGetSessionkey.Document.GetElementsByTagName("div");
foreach (HtmlElement he in hec)
{
....//在这里作个过滤,把东东取出来
}
祝你好运。。。。 --------------------编程问答-------------------- --------------------编程问答-------------------- webbrowser很难控制的.找其他方法 --------------------编程问答-------------------- 你把
function turnSas(url)
{
window.open(url);
}
这个函数改了就可以获得url吧
function turnSas(url)
{
return url;
}
要是页面是别人的内容,你注入自己的函数替换 --------------------编程问答-------------------- 我也遇到类似这样的问题
http://bbs.csdn.net/topics/390387897
不过还是没解决。。
补充:.NET技术 , C#