Changing the CSS in UIWebView

Discussion in 'iOS Programming' started by cstromme, Oct 11, 2009.

  1. cstromme macrumors regular

    Feb 26, 2007
    So I have a class here that downloads a file from a webpage, and then I use loadHTMLString and set the baseurl to main bundle path where my custom css file is.

    This works swell for the specific page I want to display with that class, but then I run into another problem.

    I have a page with a form used to post a message to a specific forum, but they've disabled off-site posting, so I can't use loadHTMLString (even if I set the baseurl to the host of the page), so the only way for some of the elements on the page to work and the posting itself I need to use loadRequest.

    But when using loadRequest I'm not able to specify a custom css file, so how would I solve this?

    So far I've been able to think up 3 ways of doing this, but I can't seem to figure out how to do any of them, or even if any of them are possible.

    1. Specifying a custom CSS file for my UIWebView
    2. Editing the received data before UIWebView starts parsing it and change it so that the line where it specifies the css file will point to my custom css file (much like I do now when I use loadHTMLString)
    3. Intercept requests for the default css file that the page uses and redirect that request to my custom css file

    Are any of these doable? If so, how?
  2. cstromme thread starter macrumors regular

    Feb 26, 2007
    Managed to solve this by using my own NSURLCache and then just intercepting any calls to the specific url for the CSS file and replacing the data with data from my own CSS file. :)
  3. punkassjim macrumors newbie

    Jul 2, 2007
    San Francisco, CA
    Can you share any more details about how you did this?

    Also, in the pages you're manipulating, are there any cookies involved? And if so, is the cookie data stripped away by your method?

Share This Page