How can I pop up Webkit's Web Inspector from my WebView object programmatically?

后端 未结 3 1762
我在风中等你
我在风中等你 2020-12-28 10:07

How can I pop up Webkit\'s Web Inspector from my WebView object programmatically?

I succeed to enable Webkit\'s Web Inspector on my WebView. It\'s working well, and

3条回答
  •  我在风中等你
    2020-12-28 10:55

    For those confused by @alex MacCaw's answer (it is c++), here is a more "normal" version..

    in your .m file... declare the WebInspector header methods..

    @interface WebInspector : NSObject  { WebView *_webView; }
    - (id)initWithWebView:(WebView *)webView;
    - (void)detach:     (id)sender;
    - (void)show:       (id)sender;
    - (void)showConsole:(id)sender;
    @end
    

    Then in that same file, be it your app delegate, or WebView subclass, or whatever... declare an ivar to "hold your inspector, and make a method to open it, using YOUR web view instance or property, or whatever. ...

    @implementation AppController  { WebInspector *_inspector; }
    
    - (IBAction)showInspector:(id)x {
       _inspector = _inspector = [WebInspector.alloc initWithWebView:_myWebView];
      [_inspector      detach:_myWebView];
      [_inspector showConsole:_myWebView];
    }
    ....
    

提交回复
热议问题