Mac Developer Library

Developer

WebKit Framework Reference WebPreferences Class Reference

Options
Deployment Target:

On This Page
Language:

WebPreferences

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 autosaves 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 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.

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

    Declaration

    Swift

    class func standardPreferences() -> WebPreferences!

    Objective-C

    + (WebPreferences *)standardPreferences

    Return Value

    A WebPreferences object containing the standard set of preferences that may be used by all WebView objects.

    Availability

    Available in OS X v10.2 and later.

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

    Declaration

    Swift

    init!(identifier anIdentifier: String!)

    Objective-C

    - (instancetype)initWithIdentifier:(NSString *)anIdentifier

    Parameters

    anIdentifier

    A unique identifier for the WebPreferences object

    Return Value

    A newly initialized WebPreferences object with the identifier; if an existing WebPreferences object with that identifier exists, it is returned instead.

    Discussion

    The anIdentifier argument should be unique—it is prepended to the keys used to store the receiver’s attributes in the user defaults database. WebView objects can share a WebPreferences object 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

    Available in OS X v10.2 and later.

    See Also

    identifier

  • A Boolean that indicates whether or not the receiver’s attributes are automatically stored in the user defaults database.

    Declaration

    Swift

    var autosaves: Bool

    Objective-C

    @property(nonatomic) BOOL autosaves

    Discussion

    YEStrue if the receiver’s attributes are automatically stored, NOfalse otherwise.

    The default value is NOfalse.

    Availability

    Available in OS X v10.2 and later.

  • A Boolean that indicates whether or not the web view allows Java.

    Declaration

    Swift

    var javaEnabled: Bool

    Objective-C

    @property(nonatomic, getter=isJavaEnabled) BOOL javaEnabled

    Discussion

    Set to YEStrue to indicate that the web view allows Java, otherwise NOfalse.

    Availability

    Available in OS X v10.2 and later.

  • A Boolean that indicates whether or not the web view allows JavaScript.

    Declaration

    Swift

    var javaScriptEnabled: Bool

    Objective-C

    @property(nonatomic, getter=isJavaScriptEnabled) BOOL javaScriptEnabled

    Discussion

    Set to YEStrue if the web view should allow JavaScript, otherwise NOfalse.

    Availability

    Available in OS X v10.2 and later.

  • A Boolean that indicates whether or not the web view allows JavaScript to open windows automatically.

    Declaration

    Swift

    var javaScriptCanOpenWindowsAutomatically: Bool

    Objective-C

    @property(nonatomic) BOOL javaScriptCanOpenWindowsAutomatically

    Discussion

    Set to YEStrue if the web view should allow JavaScript to open windows automatically, otherwise NOfalse.

    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

    Available in OS X v10.2 and later.

  • A Boolean that indicates whether or not the web view allows plug-ins.

    Declaration

    Swift

    var plugInsEnabled: Bool

    Objective-C

    @property(nonatomic, getter=arePlugInsEnabled) BOOL plugInsEnabled

    Discussion

    Set to YEStrue if the web view should allow plug-ins, otherwise NOfalse.

    Availability

    Available in OS X v10.2 and later.

  • A Boolean that indicates whether or not user style sheets are enabled in the web view.

    Declaration

    Swift

    var userStyleSheetEnabled: Bool

    Objective-C

    @property(nonatomic) BOOL userStyleSheetEnabled

    Discussion

    Set to YEStrue if the user style sheets should be enabled in the web view, otherwise NOfalse.

    Availability

    Available in OS X v10.2 and later.

  • The cursive font family of the web view.

    Declaration

    Swift

    var cursiveFontFamily: String!

    Objective-C

    @property(nonatomic, copy) NSString *cursiveFontFamily

    Discussion

    This preference affects text whose properties indicate that it should be displayed in a cursive font but do not specify a particular font.

    Availability

    Available in OS X v10.2 and later.

  • The fantasy font family of the web view.

    Declaration

    Swift

    var fantasyFontFamily: String!

    Objective-C

    @property(nonatomic, copy) NSString *fantasyFontFamily

    Discussion

    This preference affects text whose properties indicate that it should be displayed in a fantasy font but do not specify a particular font.

    Availability

    Available in OS X v10.2 and later.

  • The fixed font family of the web view.

    Declaration

    Swift

    var fixedFontFamily: String!

    Objective-C

    @property(nonatomic, copy) NSString *fixedFontFamily

    Discussion

    This preference affects text whose properties indicate that it should be displayed in a fixed font but do not specify a particular font.

    Availability

    Available in OS X v10.2 and later.

  • The sans serif font family of the web view.

    Declaration

    Swift

    var sansSerifFontFamily: String!

    Objective-C

    @property(nonatomic, copy) NSString *sansSerifFontFamily

    Discussion

    This preference affects text whose properties indicate that it should be displayed in a sans-serif font but do not specify a particular font.

    Availability

    Available in OS X v10.2 and later.

  • The serif font family of the web view.

    Declaration

    Swift

    var serifFontFamily: String!

    Objective-C

    @property(nonatomic, copy) NSString *serifFontFamily

    Discussion

    This preference affects text whose properties indicate that it should be displayed in a serif font but do not specify a particular font.

    Availability

    Available in OS X v10.2 and later.

  • The standard font family of the web view.

    Declaration

    Swift

    var standardFontFamily: String!

    Objective-C

    @property(nonatomic, copy) NSString *standardFontFamily

    Discussion

    This preference affects text whose properties do not indicate that they should be displayed in a particular font or class of fonts (such as sans-serif).

    Availability

    Available in OS X v10.2 and later.

  • The default fixed font size of the web view.

    Declaration

    Swift

    var defaultFixedFontSize: Int32

    Objective-C

    @property(nonatomic) int defaultFixedFontSize

    Discussion

    The default font size to use for content displayed in a fixed font if no font size is specified.

    Availability

    Available in OS X v10.2 and later.

  • The default font size of the web view.

    Declaration

    Swift

    var defaultFontSize: Int32

    Objective-C

    @property(nonatomic) int defaultFontSize

    Discussion

    The default font size to use for content displayed in a fixed font if no font size or font family is specified.

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

    Availability

    Available in OS X v10.2 and later.

  • The minimum font size of the web view.

    Declaration

    Swift

    var minimumFontSize: Int32

    Objective-C

    @property(nonatomic) int minimumFontSize

    Discussion

    This sets the minimum display font size for the web view, overriding all content-specified styles, including explicitly specified font sizes.

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

    Availability

    Available in OS X v10.2 and later.

  • The minimum logical font size of the web view.

    Declaration

    Swift

    var minimumLogicalFontSize: Int32

    Objective-C

    @property(nonatomic) int minimumLogicalFontSize

    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 imprecisely specified. This includes content with logical sizes (such as small) or with a font size specified as a percentage of the default.

    Most clients will not want to use this ; rather, explicitly set the minimum display font size using the minimumFontSize property.

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

    Availability

    Available in OS X v10.3 and later.

  • A Boolean that indicates whether incremental rendering should be suppressed.

    Declaration

    Swift

    var suppressesIncrementalRendering: Bool

    Objective-C

    @property(nonatomic) BOOL suppressesIncrementalRendering

    Discussion

    Pass YEStrue to suppress incremental rendering, or NOfalse otherwise.

    Availability

    Available in OS X v10.8 and later.

  • A Boolean that indicates whether or not the web view should include backgrounds when printing.

    Declaration

    Swift

    var shouldPrintBackgrounds: Bool

    Objective-C

    @property(nonatomic) BOOL shouldPrintBackgrounds

    Discussion

    Set to YEStrue if the web view should print backgrounds, otherwise NOfalse.

    Availability

    Available in OS X v10.3 and later.

  • A Boolean that indicates whether or not private browsing is enabled.

    Declaration

    Swift

    var privateBrowsingEnabled: Bool

    Objective-C

    @property(nonatomic) BOOL privateBrowsingEnabled

    Discussion

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

    Availability

    Available in OS X v10.3 and later.

  • A Boolean that indicates whether or not the tab key will focus links.

    Declaration

    Swift

    var tabsToLinks: Bool

    Objective-C

    @property(nonatomic) BOOL tabsToLinks

    Discussion

    YEStrue if the user should be able to navigate to links by pressing the tab key, NOfalse otherwise.

    Availability

    Available in OS X v10.3 and later.

  • A Boolean that indicates whether the web views associated with the receiver should use the shared page cache.

    Declaration

    Swift

    var usesPageCache: Bool

    Objective-C

    @property(nonatomic) BOOL usesPageCache

    Discussion

    YEStrue if the web views should use a page cache; otherwise, NOfalse.

    Pages are cached when they are added to a back-forward list, and removed from the cache when they are removed from a back-forward list. Because the page cache is global, caching a page in one back-forward list may cause a page in another back-forward list to be removed from the cache.

    Availability

    Available in OS X v10.5 and later.

  • The cache model for the web views associated with the receiver.

    Declaration

    Swift

    var cacheModel: WebCacheModel

    Objective-C

    @property(nonatomic) WebCacheModel cacheModel

    Discussion

    Possible values are described in WebCacheModel.

    Set this property to optimize WebKit's cache footprint (on disk and in memory) to best fit the use of the web view. If a web view is used only for a single webpage, use the WebCacheModelDocumentViewer constant instead.

    Availability

    Available in OS X v10.5 and later.

Data Types

  • Specifies the caching model for a web view.

    Declaration

    Swift

    enum WebCacheModel : UInt { case DocumentViewer case DocumentBrowser case PrimaryWebBrowser }

    Objective-C

    enum { WebCacheModelDocumentViewer = 0, WebCacheModelDocumentBrowser = 1, WebCacheModelPrimaryWebBrowser = 2 }; typedef NSUInteger WebCacheModel;

    Constants

    • documentViewer

      WebCacheModelDocumentViewer

      Releases resources when they are no longer referenced and caches remote resources on disk. This model is appropriate for displaying a static document with no navigation user interface. This is the most memory-efficient model.

      Available in OS X v10.5 and later.

    • documentBrowser

      WebCacheModelDocumentBrowser

      Caches a reasonable number of resources and previously viewed documents in memory and on disk. This model is appropriate for displaying and navigating between multiple documents.

      Available in OS X v10.5 and later.

    • primaryWebBrowser

      WebCacheModelPrimaryWebBrowser

      Caches a large number of resources and previously viewed documents in memory and on disk. This model is appropriate for a web view that behaves like a web browser.

      Available in OS X v10.5 and later.

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.5 and later.

  • 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.

    Declaration

    Swift

    let WebPreferencesChangedNotification: String

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 and later.