Search.../

link

Sets or gets the element's link.

Description

When the element is clicked, the browser navigates to the link location.

The different types of links you can use are:

  • /localPageURL: another page on your site
  • /: your site's home page
  • http(s)://<url>: an external web address
  • wix:document://<location>: a document stored in the Media Manager
  • mailto:<email-address>?subject=<subject>: an email
  • tel:<phone number>: a phone number

The link property attempts to properly encode the URL value that you set. For example, .../some page is encoded to .../some%20page. However, some URLs do not have one unambiguous encoding. In those cases it is up to you to encode the URL to reflect your intentions. Because of these situations, it is a best practice to always encode URLs before you set them as the value of the link property. Regardless of how you set the link property, when you get its value, it returns an encoded URL.

Note that Wix URLs do not contain spaces. A page which has spaces in its name has its spaces replaced with dashes (-). Similarly, a dynamic page URL(https://support.wix.com/en/article/wix-code-about-setting-up-dynamic-page-urls" target="_black) which contains the value of a field in your collection with spaces has its spaces replaced with dashes (-).

Type:

stringRead & Write, default value is An empty string
Mixed in from:$w.LinkableMixin

Related Content:

Was this helpful?

Get the link URL from an element

Code Example

Copy Code
1let url = $w("#myElement").link; // "http://mysite.com"
Set an element to open a local link

Code Example

Copy Code
1$w("#myElement").link = "/about-me";
Set an element to open an external web link

Code Example

Copy Code
1$w("#myElement").link = "http://wix.com";
Set an element to open an external web link in a new browser page when clicked

Code Example

Copy Code
1$w("#myElement").link = "http://wix.com";
2$w("#myElement").target = "_blank";
Set an element to open a new email window when clicked

Code Example

Copy Code
1$w("#myElement").link = "mailto:a@b.com?subject=Something%20Intersting";
Set an element to open a document

Code Example

Copy Code
1$w("#myElement").link = "wix:document://v1/9bec_52fb06ea/filename.xls";
Set an element to make a phone call when clicked

Code Example

Copy Code
1$w("#myElement").link = "tel:+1-555-555-5555";