Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Next Page > Hide TOC

WebPreferences Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/WebKit.framework
Availability
Available in Mac OS X v10.2 with Safari 1.0 and later.
Available in Mac OS X v10.2.7 and later.
Companion guide
Declared in
WebPreferences.h

Overview

WebPreferences encapsulates the preferences you can change per WebView object. These preferences include font, text encoding, and image settings. Normally a WebView object uses the standard preferences returned by the standardPreferences class method. However, you can modify the preferences for individual WebView instances too. Use the setPreferencesIdentifier: WebView method to change a WebView object’s preferences, or to share preferences between WebView objects. Use the setAutosaves: method to specify if the preferences object should be automatically saved to the user defaults database.

WebPreferences also manages the font preferences for a web view. You can set custom font families for each of the primary web font styles (standard, serif, sans-serif, cursive, and fantasy) as well as their font sizes. The font size preferences alter the display font sizes in a certain way. If the HTML or CSS in the web view’s content specifies font sizes in a relative fashion (such as font size=-1 in HTML or font-size: medium in CSS), the default font size settings (set by the font size methods prefaced with “default”) have an effect. They do not have an effect for font sizes specified absolutely. The values specified by the minimum font size settings (set by the font size methods prefaced with “minimum”) override all the HTML and CSS font size definitions, and so have an effect on the entirety of the content. The values specified by the minimum logical font size settings (set by the font size methods prefaced with “minimumLogical”) affect all relative font size declarations for HTML and CSS, but also override any CSS font size declarations in the content, whether they are relative or absolute.

The font size for a web view is different than its logical font size. The minimum logical font size, for example, is the absolute minimum size at which the font will display onscreen. This is meant to be a functional boundary and not a style boundary. For example, the default value for a web view’s minimum logical font size is 9 points, because typical web content looks good on Mac OS X at font sizes of 9 point and above. The constraint assures that web content will always look good in a web view. If you know that your content will look good only at 12 points or above, you should change the minimum font size to 12 points and leave the minimum logical font size alone. This will assure that your content will never display at sizes less than 12 points, but the functional font size boundary of the web view will remain at 9 points to prevent any chance of displaying unnecessarily small text.

Adopted Protocols

NSCoding

Tasks

Getting the Standard Preferences

Initializing Preferences

Getting the Identifier

Saving Preferences to the User Defaults Database

Enabling Java

Enabling JavaScript

Enabling Plug-ins

Enabling Style Sheets

Getting and Setting Fonts

Getting and Setting Font Sizes

Getting and Setting Text Encoding

Handling Images

Printing Backgrounds

Enabling Private Browsing

Controlling User Focus

Class Methods

standardPreferences

Returns the standard set of preferences that may be used by all WebView objects.

+ (WebPreferences *)standardPreferences

Availability
Declared In
WebPreferences.h

Instance Methods

allowsAnimatedImageLooping

Returns whether or not the web view allows animated images to loop.

- (BOOL)allowsAnimatedImageLooping

Discussion

The number of times that an image loops is determined by parameters of the image file itself and cannot be set in the web view.

Availability
See Also
Declared In
WebPreferences.h

allowsAnimatedImages

Returns whether or not the web view allows animated images.

- (BOOL)allowsAnimatedImages

Availability
See Also
Declared In
WebPreferences.h

arePlugInsEnabled

Returns whether or not the web view allows plug-ins.

- (BOOL)arePlugInsEnabled

Availability
See Also
Declared In
WebPreferences.h

autosaves

Returns whether or not the receiver’s attributes are automatically stored in the user defaults database.

- (BOOL)autosaves

Availability
See Also
Declared In
WebPreferences.h

cursiveFontFamily

Returns the cursive font family for the web view.

- (NSString *)cursiveFontFamily

Availability
See Also
Declared In
WebPreferences.h

defaultFixedFontSize

Returns the default fixed font size for the web view.

- (int)defaultFixedFontSize

Availability
See Also
Declared In
WebPreferences.h

defaultFontSize

Returns the default font size for the web view.

- (int)defaultFontSize

Availability
See Also
Declared In
WebPreferences.h

defaultTextEncodingName

Returns the default text encoding for the web view.

- (NSString *)defaultTextEncodingName

Availability
See Also
Declared In
WebPreferences.h

fantasyFontFamily

Returns the fantasy font family for the web view.

- (NSString *)fantasyFontFamily

Availability
See Also
Declared In
WebPreferences.h

fixedFontFamily

Returns the fixed font family for the web view.

- (NSString *)fixedFontFamily

Availability
See Also
Declared In
WebPreferences.h

identifier

Returns the receiver’s identifier.

- (NSString *)identifier

Availability
See Also
Declared In
WebPreferences.h

initWithIdentifier:

Returns an initialized WebPreferences object, creating one if it does not exist.

- (id)initWithIdentifier:(NSString *)anIdentifier

Discussion

This method returns either the receiver initialized with anIdentifier, or another WebPreferences object matching anIdentifier if it exists.

The anIdentifier argument should be a unique identifier—it will be prepended to the keys used to store the receiver’s attributes in the user defaults database. WebView objects can share instances of WebPreferences by using the same preferences identifier.

Typically, you do not invoke this method directly. Instead, you set the preferences identifier by sending a setPreferencesIdentifier: message to your WebView object. This method is the designated initializer for the WebPreferences class.

Availability
See Also
Declared In
WebPreferences.h

isJavaEnabled

Returns whether or not Java is enabled for the web view.

- (BOOL)isJavaEnabled

Availability
See Also
Declared In
WebPreferences.h

isJavaScriptEnabled

Returns whether or not JavaScript is enabled for the web view.

- (BOOL)isJavaScriptEnabled

Availability
See Also
Declared In
WebPreferences.h

javaScriptCanOpenWindowsAutomatically

Returns whether or not JavaScript can open windows automatically for the web view.

- (BOOL)javaScriptCanOpenWindowsAutomatically

Discussion

Explicit calls to a JavaScript window opener that are activated by user action (such as a button click) are not affected by this setting.

Availability
See Also
Declared In
WebPreferences.h

loadsImagesAutomatically

Returns whether images are loaded automatically for the web view.

- (BOOL)loadsImagesAutomatically

Availability
See Also
Declared In
WebPreferences.h

minimumFontSize

Returns the minimum font size for the web view.

- (int)minimumFontSize

Discussion

The default value is 1, meaning the minimum font size will only be constrained by the minimum logical font size.

Availability
See Also
Declared In
WebPreferences.h

minimumLogicalFontSize

Returns the minimum logical font size for the web view.

- (int)minimumLogicalFontSize

Discussion

The minimum logical font size is the smallest font size that will display in a Web Kit view when the content’s font size is not explicitly defined. Its default value is a 9-point font size.

Availability
See Also
Declared In
WebPreferences.h

privateBrowsingEnabled

Returns whether or not private browsing is enabled.

- (BOOL)privateBrowsingEnabled

Discussion

Private browsing prevents the web view from maintaining any history, cache, or AutoFill information for the pages being visited.

Availability
See Also
Declared In
WebPreferences.h

sansSerifFontFamily

Returns the sans serif font family for the web view.

- (NSString *)sansSerifFontFamily

Availability
See Also
Declared In
WebPreferences.h

serifFontFamily

Returns the serif font family for the web view.

- (NSString *)serifFontFamily

Availability
See Also
Declared In
WebPreferences.h

setAllowsAnimatedImageLooping:

Sets whether or not the receiver allows animated images to loop.

- (void)setAllowsAnimatedImageLooping:(BOOL)flag

Discussion

If flag is YES the web view will loop animated images, otherwise it will display them as static images. The number of times that an image loops is determined by parameters of the image file itself and cannot be set in the web view.

Availability
See Also
Declared In
WebPreferences.h

setAllowsAnimatedImages:

Sets whether or not the receiver allows animated images.

- (void)setAllowsAnimatedImages:(BOOL)flag

Discussion

If flag is YES the web view allows animated images, otherwise it does not.

Availability
See Also
Declared In
WebPreferences.h

setAutosaves:

Sets whether or not the receiver’s attributes are stored in the user defaults database.

- (void)setAutosaves:(BOOL)flag

Discussion

If flag is YES the receiver’s attributes are automatically stored in the user defaults database, otherwise they are not. The default value is NO.

Availability
See Also
Declared In
WebPreferences.h

setCursiveFontFamily:

Sets the cursive font family of the web view.

- (void)setCursiveFontFamily:(NSString *)family

Availability
See Also
Declared In
WebPreferences.h

setDefaultFixedFontSize:

Sets the default fixed font size of the web view.

- (void)setDefaultFixedFontSize:(int)size

Discussion

The font size specified by size should always be greater than zero.

Availability
See Also
Declared In
WebPreferences.h

setDefaultFontSize:

Sets the default font size of the web view.

- (void)setDefaultFontSize:(int)size

Discussion

The font size specified by size should always be greater than zero.

Availability
See Also
Declared In
WebPreferences.h

setDefaultTextEncodingName:

Sets the default text encoding of the web view.

- (void)setDefaultTextEncodingName:(NSString *)encoding

Availability
See Also
Declared In
WebPreferences.h

setFantasyFontFamily:

Sets the fantasy font family of the web view.

- (void)setFantasyFontFamily:(NSString *)family

Availability
See Also
Declared In
WebPreferences.h

setFixedFontFamily:

Sets the fixed font family of the web view.

- (void)setFixedFontFamily:(NSString *)family

Availability
See Also
Declared In
WebPreferences.h

setJavaEnabled:

Sets whether or not the web view allows Java.

- (void)setJavaEnabled:(BOOL)flag

Discussion

If flag is YES the web view allows Java, otherwise it does not.

Availability
See Also
Declared In
WebPreferences.h

setJavaScriptCanOpenWindowsAutomatically:

Sets whether or not the web view allows JavaScript to open windows automatically.

- (void)setJavaScriptCanOpenWindowsAutomatically:(BOOL)flag

Discussion

If flag is YES the web view allows JavaScript to open windows automatically, otherwise it does not. Explicit calls to a JavaScript window opener that are activated by user action (such as a button click) are not affected by this setting.

Availability
See Also
Declared In
WebPreferences.h

setJavaScriptEnabled:

Sets whether or not the web view allows JavaScript.

- (void)setJavaScriptEnabled:(BOOL)flag

Discussion

If flag is YES the web view allows JavaScript, otherwise it does not.

Availability
See Also
Declared In
WebPreferences.h

setLoadsImagesAutomatically:

Sets whether or not the web view allows images to be loaded automatically.

- (void)setLoadsImagesAutomatically:(BOOL)flag

Discussion

If flag is YES the web view allows images to be loaded automatically, otherwise it does not.

Availability
See Also
Declared In
WebPreferences.h

setMinimumFontSize:

Sets the minimum font size of the web view.

- (void)setMinimumFontSize:(int)size

Discussion

You should use this method to explicitly set the minimum display font size for the web view. The font size specified by size should always be greater than zero.

Availability
See Also
Declared In
WebPreferences.h

setMinimumLogicalFontSize:

Sets the minimum logical font size of the web view.

- (void)setMinimumLogicalFontSize:(int)size

Discussion

The minimum logical font size is the smallest font size that will display in a web view when the content’s font size is not explicitly defined. Most clients will not want to use this method; rather, explicitly set the minimum display font size using the setMinimumFontSize: method.

The font size specified by size should always be greater than zero.

Availability
See Also
Declared In
WebPreferences.h

setPlugInsEnabled:

Sets whether or not the web view allows plug-ins.

- (void)setPlugInsEnabled:(BOOL)flag

Discussion

If flag is YES the web view allows plug-ins, otherwise it does not.

Availability
See Also
Declared In
WebPreferences.h

setPrivateBrowsingEnabled:

Sets whether or not private browsing is enabled.

- (void)setPrivateBrowsingEnabled:(BOOL)flag

Discussion

If flag is YES, the web view will not store information about the websites the user visits. Private browsing prevents the web view from maintaining any history, cache, or AutoFill information for the pages being visited.

Availability
See Also
Declared In
WebPreferences.h

setSansSerifFontFamily:

Sets the sans serif font family of the web view.

- (void)setSansSerifFontFamily:(NSString *)family

Availability
See Also
Declared In
WebPreferences.h

setSerifFontFamily:

Sets the serif font family of the web view.

- (void)setSerifFontFamily:(NSString *)family

Availability
See Also
Declared In
WebPreferences.h

setShouldPrintBackgrounds:

Sets whether or not the web view should include backgrounds when printing.

- (void)setShouldPrintBackgrounds:(BOOL)flag

Discussion

If flag is YES the web view prints the backgrounds, otherwise it does not.

Availability
See Also
Declared In
WebPreferences.h

setStandardFontFamily:

Sets the standard font family of the web view.

- (void)setStandardFontFamily:(NSString *)family

Availability
See Also
Declared In
WebPreferences.h

setTabsToLinks:

Sets whether or not the web view will focus control on links when tabbing.

- (void)setTabsToLinks:(BOOL)flag

Discussion

If flag is YES the web view tabs to links, otherwise it does not.

Availability
See Also
Declared In
WebPreferences.h

setUserStyleSheetEnabled:

Sets whether or not the web view enables user style sheets.

- (void)setUserStyleSheetEnabled:(BOOL)flag

Discussion

If flag is YES the web view enables user style sheets, otherwise it does not.

Availability
See Also
Declared In
WebPreferences.h

setUserStyleSheetLocation:

Sets the location of the user style sheet.

- (void)setUserStyleSheetLocation:(NSURL *)URL

Discussion

The user style sheet will override all existing CSS definitions on the page. setUserStyleSheetEnabled: must have already been set to YES for this method to have an effect.

Availability
See Also
Declared In
WebPreferences.h

shouldPrintBackgrounds

Returns whether the web view should include backgrounds when printing.

- (BOOL)shouldPrintBackgrounds

Availability
See Also
Declared In
WebPreferences.h

standardFontFamily

Returns the standard font family used by the web view.

- (NSString *)standardFontFamily

Availability
See Also
Declared In
WebPreferences.h

tabsToLinks

Returns whether or not the tab key will focus links.

- (BOOL)tabsToLinks

Availability
See Also
Declared In
WebPreferences.h

userStyleSheetEnabled

Returns whether the web view enables user style sheets.

- (BOOL)userStyleSheetEnabled

Availability
See Also
Declared In
WebPreferences.h

userStyleSheetLocation

Returns the location of the user style sheet.

- (NSURL *)userStyleSheetLocation

Availability
See Also
Declared In
WebPreferences.h

Notifications

WebPreferencesChangedNotification

Posted when the web preference settings are changed.

The notification object is the WebPreferences object that changed. This notification does not contain a userInfo dictionary.

Availability
Declared In
WebPreferences.h

Next Page > Hide TOC


Last updated: 2006-05-23




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice