<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/DOMDocument/url(withAttributeString:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)DOMDocument(im)URLWithAttributeString:"
  },
  "title" : "url(withAttributeString:)"
}
-->

# url(withAttributeString:)

Constructs a URL given an attribute string.

```
func url(withAttributeString string: String!) -> URL!
```

## Parameters

`string`

The HTML attribute string to convert.

## Return Value

An `NSURL` object containing an absolute URL derived from the specified attribute string.

## Discussion

This method constructs a URL given the string value of an element attribute. Examples include the `href` attribute of a `DOMHTMLAnchorElement` object, or the `src` attribute of a `DOMHTMLImageElement` object. This method only applies to attributes that refer to URLs.

This method is similar to <doc://com.apple.documentation/documentation/Foundation/NSURL/init(string:)> in the `NSURL` class, except that `URLWithAttributeString:` handles relative URLs automatically based on the current document’s location.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)