Mac Developer Library

Developer

WebKit Framework Reference WebView Class Reference

Options
Deployment Target:

On This Page
Language:

WebView

WebView is the core view class in the WebKit framework that manages interactions between the WebFrame and WebFrameView classes. To embed web content in your application, you just create a WebView object, attach it to a window, and send a loadRequest: message to its main frame.

Behind the scenes, WebFrame objects encapsulate the content contained in a single frame element. A hierarchy of WebFrame objects is used to model an entire webpage where the root is called the main frame. There is a WebFrameView object per WebFrame object used to display the frame content. Therefore, there is a parallel hierarchy of WebFrameView objects used to render an entire page. The WebView object is also the parent view of this hierarchy. You do not need to create WebFrame and WebFrameView objects directly. These objects are automatically created when the page loads, either programmatically or by the user clicking a link.

You customize your embedded web content by implementing WebView delegates to handle certain aspects of the process. WebView objects have multiple delegates because the process of loading a webpage is asynchronous and complicated if errors occur. All the WebView delegates use informal protocols so you only need to implement only the delegates and methods that define the behavior you wish to change—default implementations are already provided.

For example, you might want to implement the frame load and resource load delegates to monitor the load progress and display status messages. Applications that use multiple windows may want to implement a user interface delegate. See the individual informal delegate protocols for more details: WebFrameLoadDelegate Protocol Reference, WebPolicyDelegate Protocol Reference, WebResourceLoadDelegate Protocol Reference, and WebUIDelegate Protocol Reference.

Another way to monitor load progress with less control is to observe the WebViewProgressEstimateChangedNotification, WebViewProgressFinishedNotification, and WebViewProgressStartedNotification notifications. For example, you could observe these notifications to implement a simple progress indicator in your application. You update the progress indicator by invoking the estimatedProgress method to get an estimate of the amount of content that is currently loaded.

A WebView object is intended to support most features you would expect in a web browser except that it doesn’t implement the specific user interface for those features. You are responsible for implementing the user interface objects such as status bars, toolbars, buttons, and text fields. For example, a WebView object manages a back-forward list by default, and has goBack: and goForward: action methods. It is your responsibility to create the buttons that would send theses action messages. Note, there is some overhead in maintaining a back-forward list and page cache, so you should disable it if your application doesn’t use it.

You use a WebPreferences object to encapsulate the preferences of a WebView object, such as the font, text encoding, and image settings. You can modify the preferences for individual WebView objects or specify a shared WebPreferences object using the preferencesIdentifier method. Use the setAutosaves: WebPreferences method to specify whether the preferences should be automatically saved to the user defaults database.

You can also extend WebKit by implementing your own document view and representation classes for specific MIME types. Use the registerViewClass:representationClass:forMIMEType: class method to register your custom classes with a WebView object.

  • Adds the specified URL scheme to the list of local schemes.

    Declaration

    Swift

    class func registerURLSchemeAsLocal(_ scheme: String!)

    Objective-C

    + (void)registerURLSchemeAsLocal:(NSString *)scheme

    Parameters

    scheme

    The scheme to add to the list.

    Discussion

    You need to register a scheme as local to access resources with file URLs and to have the same security checks as a local file.

    Availability

    Available in OS X v10.4.11 and later.

  • Specifies the view and representation objects to be used for specific MIME types.

    Declaration

    Swift

    class func registerViewClass(_ viewClass: AnyClass!, representationClass representationClass: AnyClass!, forMIMEType MIMEType: String!)

    Objective-C

    + (void)registerViewClass:(Class)viewClass representationClass:(Class)representationClass forMIMEType:(NSString *)MIMEType

    Parameters

    viewClass

    A class conforming to the WebDocumentView protocol that displays the specified MIME types.

    representationClass

    The class conforming to WebDocumentRepresentation protocol that represents the specified MIME types.

    MIMEType

    The MIME type of the content.

    This may be a primary MIME type or subtype. For example, if MIMEType is “video/” the specified view and representation objects are used for all video types. More specific subtype mappings, such as “image/gif”, takes precedence over primary type matching, such as “image/”.

    Discussion

    After invoking this method, when MIMEType content is encountered, instances of representationClass and viewClass are created to handle and display it.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • Initializes the receiver with a frame rectangle, frame name, and group name.

    Declaration

    Swift

    init!(frame frame: NSRect, frameName frameName: String!, groupName groupName: String!)

    Objective-C

    - (instancetype)initWithFrame:(NSRect)frameRect frameName:(NSString *)frameName groupName:(NSString *)groupName

    Parameters

    frameRect

    The frame rectangle for the created view object.

    frameName

    The web frame’s name. This should not be one of the predefined frame names (see the WebFramefindFrameNamed: method for a description of their meaning), but a custom name or a name used in HTML source. This parameter can be nil.

    groupName

    An arbitrary identifier used to group related frames. For example, JavaScript running in a frame can access any other frame in the same group. It's up to the application how it chooses to scope related frames. This parameter can be nil.

    Return Value

    An initialized view object or nil if the object couldn't be created.

    Discussion

    This method is the designated initializer for the WebView class.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • Closes the web view when it’s no longer needed.

    Declaration

    Swift

    func close()

    Objective-C

    - (void)close

    Discussion

    Closes the web view by unloading its webpage and canceling any pending load requests. A closed web view no longer responds to new requests nor sends delegate messages. It is invoked automatically if the receiver’s enclosing window or host window is closed and sending shouldCloseWithWindow to the receiver returns YEStrue. Use this method to stop the receiver from loading and sending delegate messages.

    Availability

    Available in OS X v10.4.11 and later.

  • A Boolean that indicates whether the web view should close when its window or host window closes.

    Declaration

    Swift

    var shouldCloseWithWindow: Bool

    Objective-C

    @property(nonatomic) BOOL shouldCloseWithWindow

    Discussion

    If YEStrue, the web view should close; otherwise, it should not.

    Availability

    Available in OS X v10.5 and later.

  • The main frame, the root of the web frame hierarchy for this page. (read-only)

    Declaration

    Swift

    var mainFrame: WebFrame! { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebFrame *mainFrame

    Availability

    Available in OS X v10.2 and later.

  • An action method that stops the loading of any web frame content managed by the receiver.

    Declaration

    Swift

    @IBAction func stopLoading(_ sender: AnyObject?)

    Objective-C

    - (IBAction)stopLoading:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    Stops any content in the process of being loaded by the main frame or any of its children frames. Does nothing if no content is being loaded.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • Sets the receiver’s current location by obtaining a URL string from the sender.

    Declaration

    Swift

    @IBAction func takeStringURLFrom(_ sender: AnyObject?)

    Objective-C

    - (IBAction)takeStringURLFrom:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This method sets the receiver’s current location to the value obtained by sending a stringValue message to sender, then starts loading the URL returned by sender.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

    See Also

    loadRequest: (WebFrame)

  • An action method that reloads the current page.

    Declaration

    Swift

    @IBAction func reload(_ sender: AnyObject?)

    Objective-C

    - (IBAction)reload:(id)sender

    Parameters

    sender

    The object that sent this message.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • Action method that performs an end-to-end revalidation using cache-validating conditionals if possible.

    Declaration

    Swift

    @IBAction func reloadFromOrigin(_ sender: AnyObject?)

    Objective-C

    - (IBAction)reloadFromOrigin:(id)sender

    Parameters

    sender

    The object that sent this message.

    Availability

    Available in OS X v10.6 and later.

    See Also

    reloadFromOrigin (WebView)
    – reload:

  • An estimate, as a percentage, of the amount of content that is currently loaded. (read-only)

    Declaration

    Swift

    var estimatedProgress: Double { get }

    Objective-C

    @property(nonatomic, readonly) double estimatedProgress

    Discussion

    A number ranging from 0 to 1.0 and, once a load completes, 1.0 until a new load starts, at which point it resets to 0.

    The value is an estimate based on the total number of bytes expected to be received for a document, including all its possible subresources. For more accurate load progress information, implement delegates conforming to the WebFrameLoadDelegate and WebResourceLoadDelegate informal protocols.

    Availability

    Available in OS X v10.2 and later.

  • A Boolean that indicates whether the web view draws a background.

    Declaration

    Swift

    var drawsBackground: Bool

    Objective-C

    @property(nonatomic) BOOL drawsBackground

    Discussion

    If YEStrue, a default background is drawn; if NOfalse, it is not.

    Availability

    Available in OS X v10.5 and later.

  • A Boolean that inidicates whether the web view should update even when it is not in a window that is currently visible.

    Declaration

    Swift

    var shouldUpdateWhileOffscreen: Bool

    Objective-C

    @property(nonatomic) BOOL shouldUpdateWhileOffscreen

    Discussion

    If YEStrue, the web view updates regardless if it is visible. If NOfalse, it updates only if it is visible, possibly improving performance, and then updates automatically when it becomes visible. The default value is YEStrue.

    Availability

    Available in OS X v10.6 and later.

  • Sets whether to use a back-forward list.

    Declaration

    Swift

    func setMaintainsBackForwardList(_ flag: Bool)

    Objective-C

    - (void)setMaintainsBackForwardList:(BOOL)flag

    Parameters

    flag

    If NOfalse, clears the back-forward list and relinquishes ownership the page cache; otherwise, it does not.

    Discussion

    The back-forward list maintains a page cache, so applications that do not use the goForward or goBack methods should disable it.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

    See Also

    backForwardList

  • The receiver’s back-forward list. (read-only)

    Declaration

    Swift

    var backForwardList: WebBackForwardList! { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebBackForwardList *backForwardList

    Availability

    Available in OS X v10.2 and later.

  • A Boolean that indicates whether the previous location can be loaded. (read-only)

    Declaration

    Swift

    var canGoBack: Bool { get }

    Objective-C

    @property(nonatomic, readonly) BOOL canGoBack

    Discussion

    YEStrue if able to move backward; otherwise, NOfalse.

    Availability

    Available in OS X v10.2 and later.

  • Loads the previous location in the back-forward list.

    Declaration

    Swift

    func goBack() -> Bool

    Objective-C

    - (BOOL)goBack

    Return Value

    YEStrue if able to move backward; otherwise, NOfalse.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • An action method that loads the previous location in the back-forward list.

    Declaration

    Swift

    @IBAction func goBack(_ sender: AnyObject?)

    Objective-C

    - (IBAction)goBack:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This method does nothing if it is unable to move backward.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

    See Also

    – goForward:

  • A Boolean that indicates whether the next location can be loaded. (read-only)

    Declaration

    Swift

    var canGoForward: Bool { get }

    Objective-C

    @property(nonatomic, readonly) BOOL canGoForward

    Discussion

    YEStrue if able to move forward; otherwise, NOfalse.

    Availability

    Available in OS X v10.2 and later.

  • Loads the next location in the back-forward list.

    Declaration

    Swift

    func goForward() -> Bool

    Objective-C

    - (BOOL)goForward

    Return Value

    YEStrue if able to move forward; otherwise, NOfalse.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • An action method that loads the next location in the back-forward list.

    Declaration

    Swift

    @IBAction func goForward(_ sender: AnyObject?)

    Objective-C

    - (IBAction)goForward:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This method does nothing if it is unable to move forward.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

    See Also

    – goBack:

  • Loads a specific location from the back-forward list and sets it as the current item.

    Declaration

    Swift

    func goToBackForwardItem(_ item: WebHistoryItem!) -> Bool

    Objective-C

    - (BOOL)goToBackForwardItem:(WebHistoryItem *)item

    Parameters

    item

    The index of the location to load. This method sets the current item in the back-forward list to item.

    Return Value

    YEStrue if item is in the back-forward list; otherwise, NOfalse.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • The receiver’s host window.

    Declaration

    Swift

    var hostWindow: NSWindow!

    Objective-C

    @property(nonatomic, strong) NSWindow *hostWindow

    Discussion

    Your application should only use this if a web view is going to be removed from its window temporarily, and you want the web view to continue operating (for example, you don’t want to interrupt a load in progress). Since the receiver maintains a copy of hostWindow, it is your responsibility to set the host window to nil before closing the window to avoid consuming excess memory.

    For example, you might use this property if you attach a web view to an NSTabView object (as in a tabbed browser implementation). The NSTabView object takes views out of the window when they are not in the active tab, so you need to use this before the web view is removed from its window. If you don't invoke this property, plug-ins will stop operating when the web view is removed from its window.

    Availability

    Available in OS X v10.2 and later.

  • The receiver’s preferences.

    Declaration

    Swift

    var preferences: WebPreferences!

    Objective-C

    @property(nonatomic, strong) WebPreferences *preferences

    Availability

    Available in OS X v10.2 and later.

  • The identifier of the receiver’s preferences.

    Declaration

    Swift

    var preferencesIdentifier: String!

    Objective-C

    @property(nonatomic, copy) NSString *preferencesIdentifier

    Discussion

    It is fixed to the keys used to store the receiver’s preferences in the user defaults database. WebView objects can share instances of the WebPreferences class by using the same preferences identifier.

    Availability

    Available in OS X v10.2 and later.

    See Also

    setAutosaves:

  • A Boolean that indicates whether the web view is loading content. (read-only)

    Declaration

    Swift

    var loading: Bool { get }

    Objective-C

    @property(nonatomic, getter=isLoading, readonly) BOOL loading

    Discussion

    YEStrue if the web view is currently loading any resources; otherwise, NOfalse.

    Availability

    Available in OS X v10.5 and later.

  • The frame with the active selection. (read-only)

    Declaration

    Swift

    var selectedFrame: WebFrame! { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebFrame *selectedFrame

    Discussion

    If it doesn’t exist, the frame that contains a non-zero-length selection; otherwise, nil.

    Availability

    Available in OS X v10.5 and later.

  • The URL that the main frame loads.

    Declaration

    Swift

    var mainFrameURL: String!

    Objective-C

    @property(nonatomic, copy) NSString *mainFrameURL

    Discussion

    Functionally equivalent to invoking [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:URLString]]].

    Availability

    Available in OS X v10.5 and later.

  • The HTML title of the loaded page. (read-only)

    Declaration

    Swift

    var mainFrameTitle: String! { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSString *mainFrameTitle

    Discussion

    The HTML title of the loaded page. Returns @"" if the loaded document is not HTML.

    Availability

    Available in OS X v10.5 and later.

  • The site’s favicon. (read-only)

    Declaration

    Swift

    var mainFrameIcon: NSImage! { get }

    Objective-C

    @property(nonatomic, readonly, strong) NSImage *mainFrameIcon

    Availability

    Available in OS X v10.5 and later.

  • The DOM document for the main frame. (read-only)

    Declaration

    Swift

    var mainFrameDocument: DOMDocument! { get }

    Objective-C

    @property(nonatomic, readonly, strong) DOMDocument *mainFrameDocument

    Availability

    Available in OS X v10.5 and later.

  • Returns whether the receiver can display content of a given MIME type.

    Declaration

    Swift

    class func canShowMIMEType(_ MIMEType: String!) -> Bool

    Objective-C

    + (BOOL)canShowMIMEType:(NSString *)MIMEType

    Parameters

    MIMEType

    The MIME type of the content.

    Return Value

    YEStrue if the receiver can display content of the specified MIME type where MIMEType is one of the standard types like “image/gif”; otherwise, NOfalse.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • Returns a list of MIME types that WebKit renders as HTML.

    Declaration

    Swift

    class func MIMETypesShownAsHTML() -> [AnyObject]!

    Objective-C

    + (NSArray *)MIMETypesShownAsHTML

    Return Value

    An array containing NSString objects that represent the MIME types WebKit attempts to render as HTML.

    Availability

    Available in OS X v10.3.9 and later.

  • Sets the MIME types that WebKit attempts to render as HTML.

    Declaration

    Swift

    class func setMIMETypesShownAsHTML(_ MIMETypes: [AnyObject]!)

    Objective-C

    + (void)setMIMETypesShownAsHTML:(NSArray *)MIMETypes

    Parameters

    MIMETypes

    An array of NSString objects representing the MIME types. Typically, you create the MIMETypes array by adding additional types to the array returned by the MIMETypesShownAsHTML class method.

    Availability

    Available in OS X v10.3.9 and later.

  • Returns whether the receiver interprets a MIME type as HTML.

    Declaration

    Swift

    class func canShowMIMETypeAsHTML(_ MIMEType: String!) -> Bool

    Objective-C

    + (BOOL)canShowMIMETypeAsHTML:(NSString *)MIMEType

    Parameters

    MIMEType

    The MIME type of the content.

    Return Value

    YEStrue if the receiver interprets MIMEType as HTML; otherwise, NOfalse.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • A Boolean that indicates whether the document view supports different text encodings. (read-only)

    Declaration

    Swift

    var supportsTextEncoding: Bool { get }

    Objective-C

    @property(nonatomic, readonly) BOOL supportsTextEncoding

    Discussion

    YEStrue if the receiver’s document view can support different text encodings; otherwise, NOfalse.

    Availability

    Available in OS X v10.2 and later.

  • The custom text encoding name.

    Declaration

    Swift

    var customTextEncodingName: String!

    Objective-C

    @property(nonatomic, copy) NSString *customTextEncodingName

    Availability

    Available in OS X v10.2 and later.

  • The font size multiplier for text displayed in web frame view objects managed by the receiver.

    Declaration

    Swift

    var textSizeMultiplier: Float

    Objective-C

    @property(nonatomic) float textSizeMultiplier

    Discussion

    Measured as a fractional percentage value where 1.0 denotes 100%.

    Availability

    Available in OS X v10.2 and later.

  • Searches a document view for a string and highlights it if it is found.

    Declaration

    Swift

    func searchFor(_ string: String!, direction forward: Bool, caseSensitive caseFlag: Bool, wrap wrapFlag: Bool) -> Bool

    Objective-C

    - (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag

    Parameters

    string

    The search string.

    forward

    If YEStrue the direction of the search is forward; if NOfalse, the direction is backward.

    caseFlag

    If YEStrue if the search is case sensitive; otherwise, it is not.

    wrapFlag

    If YEStrue if the search wraps; otherwise, it does not.

    Return Value

    YEStrue if the search is successful; otherwise, NOfalse.

    Discussion

    The search for string begins from the current selection and continues in the direction specified by forward. The search continues across all frames.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • Returns the appropriate user-agent string for a given URL.

    Declaration

    Swift

    func userAgentForURL(_ URL: NSURL!) -> String!

    Objective-C

    - (NSString *)userAgentForURL:(NSURL *)URL

    Parameters

    URL

    The URL that you need the user-agent string for.

    Return Value

    The user-agent string for a given URL. The user-agent string is used by websites to identify the client browser.

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

    See Also

    customUserAgent

  • The receiver’s application name that is used in the user-agent string.

    Declaration

    Swift

    var applicationNameForUserAgent: String!

    Objective-C

    @property(nonatomic, copy) NSString *applicationNameForUserAgent

    Discussion

    The user-agent is used by websites to identify the client browser.

    Availability

    Available in OS X v10.2 and later.

    See Also

    customUserAgent

  • The receiver’s custom user-agent string.

    Declaration

    Swift

    var customUserAgent: String!

    Objective-C

    @property(nonatomic, copy) NSString *customUserAgent

    Discussion

    The custom user-agent string is used for all URLs. If nil, then the receiver constructs a user-agent string that produces the best rendering results for each URL.

    Availability

    Available in OS X v10.2 and later.

  • Returns a dictionary description of the element at a given point in the receiver’s coordinates.

    Declaration

    Swift

    func elementAtPoint(_ point: NSPoint) -> [NSObject : AnyObject]!

    Objective-C

    - (NSDictionary *)elementAtPoint:(NSPoint)point

    Parameters

    point

    The point to represent as a dictionary.

    Return Value

    A dictionary description of the element at point in the receiver’s coordinates.

    Availability

    Available in OS X v10.3.9 and later.

    See Also

    webView:dragDestinationActionMaskForDraggingInfo: (WebUIDelegate)
    webView:dragSourceActionMaskForPoint:

  • Moves the drag caret that indicates the destination of a drag operation to a given point.

    Declaration

    Swift

    func moveDragCaretToPoint(_ point: NSPoint)

    Objective-C

    - (void)moveDragCaretToPoint:(NSPoint)point

    Parameters

    point

    The point to move the drag caret to.

    Availability

    Available in OS X v10.3.9 and later.

  • Removes the drag caret that indicates the destination of a drag operation.

    Declaration

    Swift

    func removeDragCaret()

    Objective-C

    - (void)removeDragCaret

    Availability

    Available in OS X v10.3.9 and later.

  • Action method that copies the selected content to the general pasteboard.

    Declaration

    Swift

    func copy(_ sender: AnyObject?)

    Objective-C

    - (void)copy:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This action method copies the selected content onto the general pasteboard, in as many formats as the receiver supports. For example, a plain text object uses NSStringPboardType for plain text, and a rich text object also uses NSRTFPboardType.

    Availability

    Available in OS X v10.3.9 and later.

  • An action method that copies font information onto the font pasteboard.

    Declaration

    Swift

    func copyFont(_ sender: AnyObject?)

    Objective-C

    - (void)copyFont:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This action method copies the font information for the first character of the selection (or for the insertion point) onto the font pasteboard as NSFontPboardType.

    Availability

    Available in OS X v10.3.9 and later.

    See Also

    – pasteFont:

  • An action method that deletes selected content and puts it on the general pasteboard.

    Declaration

    Swift

    func cut(_ sender: AnyObject?)

    Objective-C

    - (void)cut:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This action method deletes the selected content and places it onto the general pasteboard, in as many formats as the receiver supports. For example, a plain text object uses NSStringPboardType for plain text, and a rich text object also uses NSRTFPboardType.

    Availability

    Available in OS X v10.3.9 and later.

  • An action method that deletes the selected content.

    Declaration

    Swift

    func delete(_ sender: AnyObject?)

    Objective-C

    - (void)delete:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    The pasteboard is unaffected by invoking this method.

    Availability

    Available in OS X v10.3.9 and later.

    See Also

    – cut:

  • An action method that pastes content from the pasteboard at the insertion point or over the selection.

    Declaration

    Swift

    func paste(_ sender: AnyObject?)

    Objective-C

    - (void)paste:(id)sender

    Parameters

    sender

    The object that sent this message.

    Availability

    Available in OS X v10.3.9 and later.

  • An action method that pastes font information from the font pasteboard.

    Declaration

    Swift

    func pasteFont(_ sender: AnyObject?)

    Objective-C

    - (void)pasteFont:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This action method pastes font information from the font pasteboard onto the selected content or insertion point of a rich text object, or over all text of the receiver.

    Availability

    Available in OS X v10.3.9 and later.

    See Also

    – copyFont:

  • An action method that pastes pasteboard content as plain text.

    Declaration

    Swift

    func pasteAsPlainText(_ sender: AnyObject?)

    Objective-C

    - (void)pasteAsPlainText:(id)sender

    Parameters

    sender

    The object that sent this message.

    Availability

    Available in OS X v10.3.9 and later.

  • An action method that pastes pasteboard content into the receiver as rich text, maintaining its attributes.

    Declaration

    Swift

    func pasteAsRichText(_ sender: AnyObject?)

    Objective-C

    - (void)pasteAsRichText:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    The text is inserted at the insertion point if there is one; otherwise, it replaces the selection.

    Availability

    Available in OS X v10.3.9 and later.

  • An action method that searches for a misspelled word in the receiver.

    Declaration

    Swift

    func checkSpelling(_ sender: AnyObject?)

    Objective-C

    - (void)checkSpelling:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This action method starts a search at the end of the selection and continues until it reaches a word suspected of being misspelled or the end of the content. If a word isn’t recognized by the spelling server, a showGuessPanel: message is sent to the receiver which opens the Guess panel and allows the user to make a correction or add the word to the local dictionary.

    Availability

    Available in OS X v10.3.9 and later.

  • An action method that shows a spelling correction panel.

    Declaration

    Swift

    func showGuessPanel(_ sender: AnyObject?)

    Objective-C

    - (void)showGuessPanel:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This action method opens the Spelling panel, allowing the user to make a correction during spell checking.

    Availability

    Available in OS X v10.3.9 and later.

  • An action method that starts speaking the selected text or all text if there’s no selection.

    Declaration

    Swift

    func startSpeaking(_ sender: AnyObject?)

    Objective-C

    - (void)startSpeaking:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    Speech continues asynchronously until the end of the text or until terminated by invoking the stopSpeaking: method. This method behaves similar to the startSpeaking: method in NSTextView.

    Availability

    Available in OS X v10.3.9 and later.

  • An action method that stops speaking that is in progress.

    Declaration

    Swift

    func stopSpeaking(_ sender: AnyObject?)

    Objective-C

    - (void)stopSpeaking:(id)sender

    Parameters

    sender

    The object that sent this message.

    Discussion

    This action method stops speech that was previously started with startSpeaking:. This method behaves similar to the stopSpeaking: method in NSTextView.

    Availability

    Available in OS X v10.3.9 and later.

  • A Boolean that indicates whether the user is allowed to edit the document.

    Declaration

    Swift

    var editable: Bool

    Objective-C

    @property(nonatomic, getter=isEditable) BOOL editable

    Discussion

    YEStrue if the receiver allows the user to edit the HTML document, NOfalse if it doesn’t.

    You can change the receiver’s document programmatically regardless of this setting.

    Normally, an HTML document is not editable unless the elements within the document are editable. This property provides a low-level way to make the contents of a WebView object editable without altering the document or DOM structure.

    Availability

    Available in OS X v10.3 and later.

  • A Boolean that indicates whether smart-space insertion and deletion is enabled.

    Declaration

    Swift

    var smartInsertDeleteEnabled: Bool

    Objective-C

    @property(nonatomic) BOOL smartInsertDeleteEnabled

    Discussion

    YEStrue if the receiver inserts or deletes space around selected words so as to preserve proper spacing and punctuation. NOfalse if it inserts and deletes exactly what’s selected.

    Availability

    Available in OS X v10.3 and later.

  • A Boolean that indicates whether the web view has continuous spell-checking enabled.

    Declaration

    Swift

    var continuousSpellCheckingEnabled: Bool

    Objective-C

    @property(nonatomic, getter=isContinuousSpellCheckingEnabled) BOOL continuousSpellCheckingEnabled

    Discussion

    YEStrue if the object has continuous spell-checking enabled; otherwise, NOfalse.

    Availability

    Available in OS X v10.3 and later.

  • The spell-checker document tag for this document. (read-only)

    Declaration

    Swift

    var spellCheckerDocumentTag: Int { get }

    Objective-C

    @property(nonatomic, readonly) NSInteger spellCheckerDocumentTag

    Discussion

    A tag identifying the receiver’s text as a document for the spell-checker server. See the NSSpellChecker and NSSpellServer class specifications for more information on how this tag is used.

    Availability

    Available in OS X v10.3 and later.

    See Also

    spellCheckerDocumentTag (NSTextView)

  • The receiver’s undo manager. (read-only)

    Declaration

    Swift

    var undoManager: NSUndoManager! { get }

    Objective-C

    @property(nonatomic, readonly, strong) NSUndoManager *undoManager

    Availability

    Available in OS X v10.3 and later.

  • The receiver’s editing delegate.

    Declaration

    Swift

    var editingDelegate: AnyObject!

    Objective-C

    @property(nonatomic, strong) id editingDelegate

    Availability

    Available in OS X v10.3 and later.

  • Returns the editable DOM object located at a given point.

    Declaration

    Swift

    func editableDOMRangeForPoint(_ point: NSPoint) -> DOMRange!

    Objective-C

    - (DOMRange *)editableDOMRangeForPoint:(NSPoint)point

    Parameters

    point

    The location of the editable DOM object.

    Return Value

    A single range object of the editable DOM object located at point in the receiver’s coordinates.

    Availability

    Available in OS X v10.3.9 and later.

  • Returns the computed style of an element and its pseudo element.

    Declaration

    Swift

    func computedStyleForElement(_ element: DOMElement!, pseudoElement pseudoElement: String!) -> DOMCSSStyleDeclaration!

    Objective-C

    - (DOMCSSStyleDeclaration *)computedStyleForElement:(DOMElement *)element pseudoElement:(NSString *)pseudoElement

    Parameters

    element

    The element whose computed style is returned.

    pseudoElement

    The pseudo element for element.

    Return Value

    An immutable object describing the computed style of element and pseudoElement according to the Cascading Style Sheets Specification at http://www.w3.org/TR/CSS21. Returns nil if the receiver doesn’t display element.

    Availability

    Available in OS X v10.3.9 and later.

  • The receiver’s CSS media property.

    Declaration

    Swift

    var mediaStyle: String!

    Objective-C

    @property(nonatomic, copy) NSString *mediaStyle

    Availability

    Available in OS X v10.3 and later.

  • The receiver’s CSS typing style.

    Declaration

    Swift

    var typingStyle: DOMCSSStyleDeclaration!

    Objective-C

    @property(nonatomic, strong) DOMCSSStyleDeclaration *typingStyle

    Discussion

    The typing style is reset automatically when the receiver’s selection changes.

    Availability

    Available in OS X v10.3 and later.

  • Returns the CSS style declaration for the specified text.

    Declaration

    Swift

    func styleDeclarationWithText(_ text: String!) -> DOMCSSStyleDeclaration!

    Objective-C

    - (DOMCSSStyleDeclaration *)styleDeclarationWithText:(NSString *)text

    Parameters

    text

    The text whose style declaration is returned.

    Return Value

    The style declaration for text.

    Availability

    Available in OS X v10.3.9 and later.

  • Applies the CSS typing style to the current selection.

    Declaration

    Swift

    func applyStyle(_ style: DOMCSSStyleDeclaration!)

    Objective-C

    - (void)applyStyle:(DOMCSSStyleDeclaration *)style

    Parameters

    style

    The style to apply to the current selection.

    Discussion

    This method does nothing if there is no current selection or if the current selection is collapsed.

    This method hides the complexities of applying styles to elements. If necessary, this method will make multiple passes over the range of the current selection to ensure that the requested style is applied to the elements in that range, and takes into account the complexities of CSS style application rules. This method also simplifies styling attributes so that the minimum number of styling directives are used to yield a given computed style.

    Availability

    Available in OS X v10.3.9 and later.

  • Predefined keys used to access an element dictionary.

    Declaration

    Swift

    let WebElementDOMNodeKey: String let WebElementFrameKey: String let WebElementImageAltStringKey: String let WebElementImageKey: String let WebElementImageRectKey: String let WebElementImageURLKey: String let WebElementIsSelectedKey: String let WebElementLinkURLKey: String let WebElementLinkTargetFrameKey: String let WebElementLinkTitleKey: String let WebElementLinkLabelKey: String

    Objective-C

    extern NSString *WebElementDOMNodeKey; extern NSString *WebElementFrameKey; extern NSString *WebElementImageAltStringKey; extern NSString *WebElementImageKey; extern NSString *WebElementImageRectKey; extern NSString *WebElementImageURLKey; extern NSString *WebElementIsSelectedKey; extern NSString *WebElementLinkURLKey; extern NSString *WebElementLinkTargetFrameKey; extern NSString *WebElementLinkTitleKey; extern NSString *WebElementLinkLabelKey;

    Constants

    • WebElementDOMNodeKey

      WebElementDOMNodeKey

      The DOMNode for this element.

      Available in OS X v10.3 and later.

    • WebElementFrameKey

      WebElementFrameKey

      The WebFrame object associated with this element.

      Available in OS X v10.2 and later.

    • WebElementImageAltStringKey

      WebElementImageAltStringKey

      An NSString of the ALT attribute of an image element.

      Available in OS X v10.2 and later.

    • WebElementImageKey

      WebElementImageKey

      An NSImage representing an image element.

      Available in OS X v10.2 and later.

    • WebElementImageRectKey

      WebElementImageRectKey

      An NSValue containing an NSRect, the size of an image element.

      Available in OS X v10.2 and later.

    • WebElementImageURLKey

      WebElementImageURLKey

      An NSURL containing the location of an image element.

      Available in OS X v10.2 and later.

    • WebElementIsSelectedKey

      WebElementIsSelectedKey

      An NSNumber used as a BOOL value to indicate whether a text element is selected or not. Zero value indicates false, true otherwise.

      Available in OS X v10.2 and later.

    • WebElementLinkURLKey

      WebElementLinkURLKey

      An NSURL containing the location of a link if the element is within an anchor.

      Available in OS X v10.2 and later.

    • WebElementLinkTargetFrameKey

      WebElementLinkTargetFrameKey

      The WebFrame object associated with the target of the anchor.

      Available in OS X v10.2 and later.

    • WebElementLinkTitleKey

      WebElementLinkTitleKey

      An NSString containing the title of an anchor.

      Available in OS X v10.2 and later.

    • WebElementLinkLabelKey

      WebElementLinkLabelKey

      An NSString containing the text within an anchor.

      Available in OS X v10.2 and later.

    Discussion

    These constants represent predefined keys used to access an element dictionary. An element dictionary is an NSDictionary representation of an HTML element, as in a clicked or selected element. Some methods in the WebPolicyDelegate informal protocol have an element dictionary argument. The descriptions below describe the dictionary value for the key.

  • Posted when a web view begins any operation that changes its contents in response to user editing. The notification object is the WebView object that the user is editing. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let WebViewDidBeginEditingNotification: String

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Posted when a web view performs any operation that changes its contents in response to user editing. The notification object is the WebView object that the user is editing. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let WebViewDidChangeNotification: String

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Posted when a web view changes its typing selection. The notification object is the WebView that changed its typing selection. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let WebViewDidChangeSelectionNotification: String

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Posted when a web view changes its typing style. The notification object is the WebView that changed its typing style. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let WebViewDidChangeTypingStyleNotification: String

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Posted when a web view ends any operation that changes its contents in response to user editing. The notification object is the WebView that the user is editing. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let WebViewDidEndEditingNotification: String

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Posted by a WebView object when the estimated progress value of a load changes. This notification may be posted zero or more times after a WebViewProgressStartedNotification notification is posted. The notification object is the WebView for which the progress value has changed. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let WebViewProgressEstimateChangedNotification: String

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • Posted by a WebView object when the load has finished. The notification object is the WebView that finished loading. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let WebViewProgressFinishedNotification: String

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.

  • Posted by a WebView object when a load begins, including a load that is initiated in a subframe. The notification object is the WebView that began loading. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let WebViewProgressStartedNotification: String

    Import Statement

    Objective-C

    @import WebKit;

    Swift

    import WebKit

    Availability

    Available in OS X v10.2 with Safari 1.0 and later.

    Available in OS X v10.2.7 and later.