• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: stripped down webview
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stripped down webview


  • Subject: Re: stripped down webview
  • From: Koen van der Drift <email@hidden>
  • Date: Sat, 18 Aug 2012 14:29:24 -0400

On Aug 18, 2012, at 1:40 PM, Kyle Sluder <email@hidden> wrote:

> This is a good start. I believe "user stylesheet" is the term of art for a local override stylesheet. From a quick Google, the relevant APIs are on the WebPreferences class: -setUserStyleSheetEnabled: and -setUserStyleSheetLocation:. You could start with one of the common "reset" stylesheets and customize it from there.


I tried that, but the settings in my css file are not used.

   WebPreferences  *prefs = [WebPreferences standardPreferences];
    [prefs setJavaScriptEnabled: YES];
    [prefs setCacheModel: WebCacheModelDocumentBrowser];
    [prefs setPlugInsEnabled: YES];

    NSString *path = [[NSBundle mainBundle] pathForResource: @"default" ofType: @"css"];
    NSURL *css = [NSURL URLWithString: path];

    [prefs setUserStyleSheetEnabled: YES];
    [prefs setUserStyleSheetLocation: css];

    [self.webView setPreferences: prefs];



So I am now hacking in the DOM, and this way I can add my stylesheet:

	NSError *error = nil;

	DOMDocument* domDocument = [webView mainFrameDocument];
	 DOMElement* styleElement = [domDocument createElement: @"style"];
	 [styleElement setAttribute: @"type" value: @"text/css"];

	NSString *path = [[NSBundle mainBundle] pathForResource: @"default" ofType: @"css"];
	 NSString *css = [NSString stringWithContentsOfFile: path encoding: NSUTF8StringEncoding error: &error];

	 DOMText *cssText = [domDocument createTextNode: css];
	[styleElement appendChild: cssText];

	DOMElement* headElement= (DOMElement*)[[domDocument getElementsByTagName: @"head"] item:0];
	[headElement appendChild:styleElement];


This way the css gets inserted into the DOM, but I still have the delay.


I am open for any suggestions/improvements :)

- Koen.






_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: stripped down webview
      • From: Jens Alfke <email@hidden>
    • Re: stripped down webview
      • From: Matt Patenaude <email@hidden>
References: 
 >stripped down webview (From: Koen van der Drift <email@hidden>)
 >Re: stripped down webview (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: help indexer or hiutil help
  • Next by Date: Re: stripped down webview
  • Previous by thread: Re: stripped down webview
  • Next by thread: Re: stripped down webview
  • Index(es):
    • Date
    • Thread