.NET WebBrowser控件JavaScript问题 [英] .NET WebBrowser control javascript issue

查看:99
本文介绍了.NET WebBrowser控件JavaScript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有基于HTML的报告,这些报告被馈送到需要使用javascript的WebBrowser控件.

我的问题是,使用WebBrowser.DocumentText时,我的JavaScript不会执行,但是使用WebBrowser.Navigate时,它会很好地执行.

有谁知道为什么会这样吗?

谢谢

HTML示例:

I have HTML based reports that get fed to the WebBrowser control that needs to use javascript.

My issue is that my javascript won''t execute when using WebBrowser.DocumentText but, executes fine when using WebBrowser.Navigate.

Does anyone know why this would happen?

Thanks

Example HTML:

<html>
<head>
<title></title>
</head>
<body>
<a href="#" onClick="alert('yeah');">Click Me</a>
</body>
</html>

推荐答案

必须是您正在做的其他事情(也许是错误的;)).我举了个小例子,它的工作原理完全符合预期:

Must be something else you''re doing ( wrong maybe ;) ). I threw toghether this small example and it works exactly as expected:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestWebBrowser
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.DocumentText = "<html><head><title></title></head><body><a href=\"#\" onClick=\"alert('yeah');\">Click Me</a></body></html>";
        }
    }
}



一个简单的窗体,上面带有WebBrowser控件,并带有使控件加载通过DocumentText提供的HTML的按钮.该窗体显示ClickMe链接,当我单击该链接时,警告框会弹出是".

最好的问候,

--MRB



A simple form with a WebBrowser control on it and a button that makes the control load the HTML you provided via DocumentText. The form shows the ClickMe link and when I click it the alert box springs up with "yeah".

Best Regards,

--MRB


这篇关于.NET WebBrowser控件JavaScript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆