首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用WebKit.NET访问DOM?

如何使用WebKit.NET访问DOM?
EN

Stack Overflow用户
提问于 2009-08-11 03:56:41
回答 1查看 2.3K关注 0票数 3

我在一个C#应用程序中使用WebKit来呈现一个CSS样式的XML文档,并且我希望能够添加DOM元素。如何访问DOM才能做到这一点?问题似乎在于WebKitBrowser类中没有提供对私有webView成员的访问权限的属性。有可能吗?我需要修改这个类才能添加这个吗?我是不是做错了?

EN

回答 1

Stack Overflow用户

发布于 2010-02-24 23:19:22

从0.3.0开始,WebKit.Net看起来不能访问codedom。我做了一些稍微不同的事情,我使用了WebKit.Net,但我在应用程序中添加了一个超文本传输协议侦听器,并且我设置了从那里检索页面的控件。通过这种方式,我可以访问同一个应用程序中的帖子和回调。剩下的我自己在页面上用JavaScript来做。

代码语言:javascript
复制
        HttpListener listener;

    public Form1( ) {
        InitializeComponent( );

        listener = new System.Net.HttpListener( );

        listener.Prefixes.Add( "http://*:88/" );
        listener.Start( );
        IAsyncResult result = listener.BeginGetContext( new AsyncCallback(  ListenerCallback ), listener );

    }

    public static void ListenerCallback( IAsyncResult result ) {

    string resp = "<body>test</body";

        HttpListener listener = ( HttpListener )result.AsyncState;

        // Call EndGetContext to complete the asynchronous operation.
        try {
            HttpListenerContext context = listener.EndGetContext( result );
            HttpListenerRequest request = context.Request;

            // Obtain a response object.
            HttpListenerResponse response = context.Response;

            // Construct a response.
            string webpage = request.Url.AbsolutePath.Substring( 1 );
            string responseString = null;
            if ( string.IsNullOrEmpty( webpage ) ) {
                responseString = resp;
            }
            else {
                webpage = webpage.Replace( ".", "_" );
                responseString = webkit_test.Properties.Resources.ResourceManager.GetResourceSet( System.Globalization.CultureInfo.CurrentCulture, true, false ).GetObject( webpage ) as string;
                if ( responseString == null ) {
                    responseString = "<html></html><body> 404 Web Page not Found</body>";
                }
            }
            byte[ ] buffer = System.Text.Encoding.UTF8.GetBytes( responseString );

            // Get a response stream and write the response to it.
            response.ContentType = "text/html; charset=UTF-8";
            response.ContentLength64 = buffer.Length;

            System.IO.Stream output = response.OutputStream;
            output.Write( buffer, 0, buffer.Length );
            output.Flush( );

            // You must close the output stream.
            output.Close( );
            IAsyncResult result1 = listener.BeginGetContext( new AsyncCallback( ListenerCallback ), listener );
        }
        catch { }
    }

顺便说一句。该代码还将从嵌入的资源中读取网页

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1258403

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档