Mac Developer Library

Developer

WebKit Framework Reference WebFrame Class Reference

Options
Deployment Target:

On This Page
Language:

WebFrame

A WebFrame object encapsulates the data displayed in a WebFrameView object. There is one WebFrame object per frame displayed in a WebView. An entire webpage is represented by a hierarchy of WebFrame objects in which the root object is called the main frame. More...

Inheritance


Conforms To


Import Statement


import WebKit @import WebKit;

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 name, web frame view, and controlling web view.

    Declaration

    Swift

    init!(name frameName: String!, webFrameView view: WebFrameView!, webView webView: WebView!)

    Objective-C

    - (instancetype)initWithName:(NSString *)frameName webFrameView:(WebFrameView *)view webView:(WebView *)webView

    Parameters

    frameName

    The frame name. Typically a custom name or nil (if none is specified). It would be inappropriate to use one of the predefined frame names described in findFrameNamed: as they have special meanings.

    view

    The view that displays this web frame—the view associated with the receiver.

    webView

    The parent view that manages the main frame and its children.

    Return Value

    An initialized web frame.

    Discussion

    Normally, you do not invoke this method directly. WebView objects automatically create the main frame and subsequent children when new content is loaded. Send a loadRequest: message to the main frame of a WebView to load web content.

    This method is the designated initializer for the WebFrame class.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

  • Connects to a given URL by initiating an asynchronous client request.

    Declaration

    Swift

    func loadRequest(_ request: NSURLRequest!)

    Objective-C

    - (void)loadRequest:(NSURLRequest *)request

    Parameters

    request

    A client request.

    Discussion

    Creates a provisional data source that will transition to a committed data source once any data has been received. Use the dataSource method to check if a committed data source is available, and the stopLoading method to stop the load. This method is typically invoked on the main frame.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

  • Reloads the initial request passed as an argument to loadRequest:.

    Declaration

    Swift

    func reload()

    Objective-C

    - (void)reload

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

  • Performs an end-to-end revalidation using cache-validating conditionals if possible.

    Declaration

    Swift

    func reloadFromOrigin()

    Objective-C

    - (void)reloadFromOrigin

    Discussion

    End-to-end reload may be necessary if the cache entry has become corrupted for some reason.

    Import Statement

    import WebKit

    Availability

    Available in OS X v10.6 and later.

  • Stops any pending loads on the receiver’s data source, and those of its children.

    Declaration

    Swift

    func stopLoading()

    Objective-C

    - (void)stopLoading

    Discussion

    This method does not change the state of the receiver—whatever content has been loaded is preserved.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

  • Loads alternate content for a frame whose URL is unreachable.

    Declaration

    Swift

    func loadAlternateHTMLString(_ string: String!, baseURL URL: NSURL!, forUnreachableURL unreachableURL: NSURL!)

    Objective-C

    - (void)loadAlternateHTMLString:(NSString *)string baseURL:(NSURL *)URL forUnreachableURL:(NSURL *)unreachableURL

    Parameters

    string

    The string to use as the main page for the document.

    URL

    A file that is used to resolve relative URLs within the document.

    unreachableURL

    The URL for the alternate page content.

    Discussion

    Use this method to display page-level loading errors in a web view. Typically, a WebFrameLoadDelegate or WebPolicyDelegate object invokes this method from these methods: webView:didFailProvisionalLoadWithError:forFrame: (WebFrameLoadDelegate), webView:decidePolicyForMIMEType:request:frame:decisionListener: (WebPolicyDelegate), or webView:unableToImplementPolicyWithError:frame: (WebPolicyDelegate). If invoked from one of these methods, the back-forward list is maintained.

    Import Statement

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Sets the main page contents and base URL.

    Declaration

    Swift

    func loadHTMLString(_ string: String!, baseURL URL: NSURL!)

    Objective-C

    - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)URL

    Parameters

    string

    The string to use as the main page for the document.

    Since the string is treated as a webpage with UTF-8 encoding, the default encoding for any script elements referenced by the HTML is also UTF-8. To avoid this, include a character set attribute on the script element.

    URL

    A file that is used to resolve relative URLs within the document.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

  • Sets the main page contents, MIME type, content encoding, and base URL.

    Declaration

    Swift

    func loadData(_ data: NSData!, MIMEType MIMEType: String!, textEncodingName encodingName: String!, baseURL URL: NSURL!)

    Objective-C

    - (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)URL

    Parameters

    data

    The data to use for the main page of the document.

    MIMEType

    The MIME type of the data.

    encodingName

    The IANA encoding name (for example, “utf-8” or “utf-16”).

    URL

    A file that is used to resolve relative URLs within the document.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

  • Loads an archive into the web frame.

    Declaration

    Swift

    func loadArchive(_ archive: WebArchive!)

    Objective-C

    - (void)loadArchive:(WebArchive *)archive

    Parameters

    archive

    The archive to load.

    Import Statement

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns the committed data source.

    Declaration

    Swift

    var dataSource: WebDataSource? { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebDataSource *dataSource

    Return Value

    The committed data source, or nil if the provisional data source is not done loading.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

  • Returns the provisional data source.

    Declaration

    Swift

    var provisionalDataSource: WebDataSource! { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebDataSource *provisionalDataSource

    Return Value

    The provisional data source, or nil if either a load request is not in progress or a load request has completed.

    Discussion

    Use the loadRequest: method to initiate an asynchronous client request, which creates a provisional data source. The provisional data source transitions to a committed data source once any data is received.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

    See Also

    – dataSource

  • Returns the web frame’s parent web frame.

    Declaration

    Swift

    var parentFrame: WebFrame! { get }

    Objective-C

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

    Return Value

    The parent web frame, or nil if it has none.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

    See Also

    – childFrames

  • Returns the frames of the web frame’s immediate children.

    Declaration

    Swift

    var childFrames: [AnyObject]! { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSArray *childFrames

    Return Value

    The web frame’s immediate children. Each child web frame is an instance of WebFrame and corresponds to an HTML frameset or iframe element.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

    See Also

    – parentFrame

  • Returns the web frame’s view object.

    Declaration

    Swift

    var frameView: WebFrameView! { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebFrameView *frameView

    Return Value

    The web frame’s view object.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

    See Also

    – webView

  • Returns the view object that manages the web frame.

    Declaration

    Swift

    var webView: WebView! { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebView *webView

    Return Value

    The view object that manages the entire hierarchy of web frame objects that contains the receiver.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

    See Also

    – frameView

  • Returns a web frame that matches the given name.

    Declaration

    Swift

    func findFrameNamed(_ name: String!) -> WebFrame!

    Objective-C

    - (WebFrame *)findFrameNamed:(NSString *)name

    Parameters

    name

    The name of a frame.

    Return Value

    For predefined names, returns the receiver if name is “_self” or “_current”, returns the receiver’s parent frame if name is “_parent”, and returns the main frame if name is “_top”. Also returns the receiver if it is the main frame and name is either “_parent” or “_top.” For other names, this method returns the first frame that matches name. Returns nil if no match is found.

    Discussion

    This method searches the receiver and its descendents first, then the receiver’s parent and its children moving up the hierarchy until a match is found. If no match is found in the receivers hierarchy, this method will search for a matching frame in other main frame hierarchies.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

    See Also

    – name

  • Returns the web frame’s name.

    Declaration

    Swift

    var name: String! { get }

    Objective-C

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

    Return Value

    The web frame’s name.

    Import Statement

    import WebKit

    Availability

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

    Available in OS X v10.2.7 and later.

  • Returns the web frame’s DOM document.

    Declaration

    Swift

    var DOMDocument: DOMDocument! { get }

    Objective-C

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

    Return Value

    The web frame’s DOM document.

    Discussion

    Returns nil if the receiver doesn’t have a DOM document; for example, if it’s a standalone image.

    Import Statement

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns the web view’s DOM frame element.

    Declaration

    Swift

    var frameElement: DOMHTMLElement! { get }

    Objective-C

    @property(nonatomic, readonly, strong) DOMHTMLElement *frameElement

    Return Value

    The web view’s DOM frame element. Returns nil if the receiver is the main frame.

    Discussion

    The returned object may be an instance of either DOMHTMLFrameElement, DOMHTMLIFrameElement or DOMHTMLObjectElement.

    Import Statement

    import WebKit

    Availability

    Available in OS X v10.3.9 and later.

  • Returns the global JavaScript execution context for bridging between the WebKit and JavaScriptCore C API.

    Declaration

    Swift

    var globalContext: JSGlobalContext! { get }

    Objective-C

    @property(nonatomic, readonly) JSGlobalContextRef globalContext

    Return Value

    The global JavaScript execution context.

    Import Statement

    import WebKit

    Availability

    Available in OS X v10.4.11 and later.

  • Returns the JavaScript window object.

    Declaration

    Swift

    var windowObject: WebScriptObject! { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebScriptObject *windowObject

    Return Value

    The JavaScript window object.

    Import Statement

    import WebKit

    Availability

    Available in OS X v10.4.11 and later.