Unable to use Console.Log() within a WebBrowser Control

前端 未结 2 1162
情歌与酒
情歌与酒 2020-12-17 04:43

So I\'m writing a Javascript coding UI using C# Windows Forms. This is my code for when the \"Run\" button is pressed, in case it helps:



        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-17 05:20

    Yes, Console class is not available in your browser control, but you can create a logger class like this

    [ComVisible(true)]
    public class Logger
    {
        public void log(string s)
        {
            Console.WriteLine(s);
        }
    }
    

    and use it in your browser control

    webBrowser1.ObjectForScripting = new Logger();
    webBrowser1.DocumentText = "";
    

提交回复
热议问题