.NET WebBrowser控件JavaScript问题 [英] .NET WebBrowser control javascript issue
问题描述
我有基于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屋!