$w.LinkableElement

$w.LinkableElement

Provides functionality related to web links used by elements.

Contents

link Sets or returns the link location that is assigned to an element.
target Determines the web link target that is assigned to an element.
link

link

Sets or returns the link location that is assigned to an element.

Syntax

let elementLink = $w("#myElement").link;
$w("#myElement").link = "mailto:"<friend@bitbucket.com>"?subject=Dinner";

Description

The link property allows you to set or get the link location assigned to elements like shapes, buttons, and images. When the element is clicked, the browser navigates to the link location.

The different types of links you can use are:

  • Web Addresshttp://<address> or https://<address>
  • Emailmailto:<email_address>?subject=<subject>
  • Documentdocument://<document—id>
  • Page / Anchor/<page—url>, /<page—url>#<anchor>, or #<anchor>

    Special anchors include:

    • Top of page — URL of the form #top
    • Bottom of page — URL of the form #bottom

Type

String

Examples

Configure a button to open an external web link in a new browser page when clicked

JHcoIiNteUJ1dHRvbiIpLmxpbmsgPSAiaHR0cDovL2NvZGUud2l4LmNvbS9kb2NzIjsKJHcoIiNteUJ1dHRvbiIpLnRhcmdldCA9ICJfYmxhbmsiOw==
$w("#myButton").link = "http://code.wix.com/docs";
$w("#myButton").target = "_blank";

Configure a shape to open a new email window when clicked

Ly8gQ29uZmlndXJlIHNoYXBlICdteVNoYXBlJyB0bywgd2hlbiBjbGlja2VkLCBjb21wb3NlIGFuIGVtYWlsOgokdygiI215U2hhcGUiKS5saW5rID0gIm1haWx0bzpqc21pdGhAd2l4LmNvbT9zdWJqZWN0PUhlbGxvIGZyb20gV2l4Ijs=
// Configure shape 'myShape' to, when clicked, compose an email:
$w("#myShape").link = "mailto:jsmith@wix.com?subject=Hello from Wix";

Configure an image to download a PDF when clicked

JHcoIiNteUltYWdlIikubGluayA9ICJkb2N1bWVudDovL2FiY2QxMjM0LnBkZiI7
$w("#myImage").link = "document://abcd1234.pdf";

Get the existing link information for a button and print it to the console

dmFyIG15VVJMID0gJHcoIiNteUJ1dHRvbiIpLmxpbms7CmNvbnNvbGUubG9nKG15VVJMKTsKCi8vIOKAoiBodHRwOi8vd3d3Lmdvb2dsZS5jb20=
var myURL = $w("#myButton").link;
console.log(myURL);

// • http://www.google.com

Default Value

An empty string

See Also

target

target

target

Determines the web link target that is assigned to an element.

Syntax

let elementTarget = $w("#myElement").target;
$w("#myElement").target = ("_blank"|"_self");

Description

The target of an element determines whether the web link assigned to this element opens in the current page or opens in a new page. Supported values are:

  • "_blank" — The link opens in a new page, leaving the current page open in its own window.
  • "_self" — The link opens in the current page.

Type

String

Examples

Configure a button to open an external web link in a new browser page when clicked

JHcoIiNteUJ1dHRvbiIpLmxpbmsgPSAiaHR0cDovL2NvZGUud2l4LmNvbS9kb2NzIjsKJHcoIiNteUJ1dHRvbiIpLnRhcmdldCA9ICJfYmxhbmsiOw==
$w("#myButton").link = "http://code.wix.com/docs";
$w("#myButton").target = "_blank";

Default Value

"_blank"

See Also

link