Injecting CSS into UIWebView using JavaScript

后端 未结 1 1328
挽巷
挽巷 2021-02-04 20:32

I am attempting to inject a local CSS file to override the styling of a webpage. The webpage is presented in a UIWebView container in iOS. However I am not able to

1条回答
  •  遇见更好的自我
    2021-02-04 20:52

    Your solution won't work because

    1. your cssNode.href should be a URL (i.e. escaped and prefixed with file://), not a path
    2. Safari doesn't let you load local files from a remote page, as it's a security risk.

    In the past I've done this by downloading the HTML using an NSURLConnection, and then adding a ", iOSCssData]; html = [uneditedHtml stringByReplacingOccurrencesOfString:@"" withString:extraHeadTags]; [webView loadHTMLString:html baseURL:url];

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