Manipulating WebKit CSS data before loading?

后端 未结 2 1689
无人及你
无人及你 2021-01-14 01:39

Is it possible to manipulate CSS data before it is parsed in WebKit?

I\'ve tried using the delegate method

- (NSURLRequest *)webView:(WebView *)send         


        
相关标签:
2条回答
  • 2021-01-14 01:56

    Just load a user style sheet to override whatever CSS you want (that's the "cascading" part of CSS). This is a core feature of WebKit.

    WebPreferences setUserStyleSheetEnabled:

    For an example of this in practice, you can look at PandoraBoy's PlayerController which has hooks for it (though I wound up not needing to actually use them). Look in -awakeFromNib.

    EDIT: If you really need to substitute your own CSS file for the original in a way that's totally transparent to WebKit, that's possible but it's a bit more work, more confusing, and generally shouldn't be needed. That said, PandoraBoy did run into this problem, and there's a solution. Look at ResourceURLProtocol.

    0 讨论(0)
  • 2021-01-14 01:57

    As long as you can keep it under the 10MB limit, there is always stringByEvaluatingJavaScriptFromString and then do some loading of the CSS dynamically.

    0 讨论(0)
提交回复
热议问题