我正在使用C# Windows Forms编写JavaScript编码UI界面。以下是当"Run"按钮被按下时的代码,希望对您有帮助:
//If the button in the upper-right corner is clicked
private void run_Click(object sender, EventArgs e)
{
//If the program isn't running
if (!running)
{
//Show the web browser
webBrowser1.Visible = true;
richTextBox1.Visible = false;
//Set the label to Running
status.Text = "Running";
//Set the html text to this below
webBrowser1.DocumentText = "<!DOCTYPE html><html><body><script>\n" + richTextBox1.Text + "\n</script></body></html>";
//Set the "run" button to "stop"
run.Text = "Stop";
//Set the status to running
running = true;
}
//otherwise
else
{
//Show the text box
webBrowser1.Visible = false;
richTextBox1.Visible = true;
//Set the label to Ready
status.Text = "Ready";
//Go to nothingness
webBrowser1.Navigate("about:blank");
//Set the "stop" button to "run"
run.Text = "Run";
//Set the status to not running
running = false;
}
}
我运行程序,大部分情况下都能正常工作。但是当我尝试使用console.log()命令时,出现以下错误:
'console' is undefined
我也尝试了 Console.Log (我其实不会 JavaScript,只是尽力而为),但是返回相同的错误,即“Console”未定义。
另外,一旦我成功让 console.log 运行,如何在 WebBrowser 控件上打开控制台?我尝试在互联网上搜索,但这两个问题都没有得到解答。